Skip to content

Instantly share code, notes, and snippets.

@44100hertz
Created January 7, 2019 08:46
Show Gist options
  • Save 44100hertz/294c2c229639206d0585185e911f4a33 to your computer and use it in GitHub Desktop.
Save 44100hertz/294c2c229639206d0585185e911f4a33 to your computer and use it in GitHub Desktop.
fn triples() -> impl Iterator<Item=(u32, u32, u32)> {
let (mut x, mut y, mut z) = (1, 1, 1);
(0..).map(move |_| {
loop {
y += 1;
if y > z {
x += 1;
y = x;
}
if x > z {
z += 1;
x = 1;
y = 1;
}
if x*x + y*y == z*z {
return (x, y, z);
}
}
})
}
fn main() {
for (x, y, z) in triples().take(1000) {
println!("({}, {}, {})", x, y, z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment