Last active
October 25, 2015 10:44
-
-
Save iwillspeak/f35b4a501b6f1fa947ab to your computer and use it in GitHub Desktop.
Now Slightly Less Hacky Brute Force of Projec Euler 12 in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "euler12" | |
version = "0.1.0" | |
[[bin]] | |
name = "euler12" | |
path = "euler12.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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