Skip to content

Instantly share code, notes, and snippets.

@iwillspeak
Last active October 25, 2015 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwillspeak/f35b4a501b6f1fa947ab to your computer and use it in GitHub Desktop.
Save iwillspeak/f35b4a501b6f1fa947ab to your computer and use it in GitHub Desktop.
Now Slightly Less Hacky Brute Force of Projec Euler 12 in Rust
[package]
name = "euler12"
version = "0.1.0"
[[bin]]
name = "euler12"
path = "euler12.rs"
fn find_divisors(n: u64) -> usize {
let rt = (n as f64).sqrt() as u64;
let mut nod = (1..rt)
.filter(|i| (n % i) == 0)
.count() * 2;
if (rt * rt) == n {
nod += 1;
}
nod
}
fn main() {
let mut n = 0;
let mut i = 1;
while find_divisors(n) < 500 {
n += i;
i += 1;
}
println!("Found {:?}", n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment