Created
September 12, 2020 07:27
-
-
Save kinoshita-lab/44af5713519b419c132920f1d771694c to your computer and use it in GitHub Desktop.
project euler problem 7
This file contains hidden or 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 is_prime(val: u64) -> bool { | |
let end = |current_val: u64| -> bool { current_val * current_val > val }; | |
let mut i = 2; | |
loop { | |
if (val % i) == 0 { | |
return false; | |
} | |
if end(i) { | |
return true; | |
} | |
i += 1; | |
} | |
} | |
fn main() { | |
let mut nth = 0; | |
let mut i = 0; | |
let goal = 10001; | |
loop { | |
i += 1; | |
if is_prime(i) { | |
nth += 1; | |
println!("{}, {}", nth, i); | |
if nth == goal { | |
println!("{}", i); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment