Skip to content

Commit f0a6e87

Browse files
committed
Use C's printf in simple.rs to provide a fair comparison.
1 parent 0e35194 commit f0a6e87

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

simple.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
extern "C" {
2+
fn printf(fmt: *const i8, ...) -> i32;
3+
}
4+
15
pub fn main() {
26
print_triples();
37
}
48

5-
69
fn print_triples() {
710
let mut i = 0 as i32;
811
for z in 1.. {
9-
for x in 1..=z {
10-
for y in x..=z {
11-
if x*x + y*y == z*z {
12-
println!("({}, {}, {})", x, y, z);
12+
for x in 1..z + 1 {
13+
for y in x..z + 1 {
14+
if x * x + y * y == z * z {
15+
unsafe { printf("(%i, %i, %i)\n".as_ptr() as *const i8, x, y, z) };
1316
i = i + 1;
1417
if i == 1000 {
1518
return;

0 commit comments

Comments
 (0)