Skip to content

Instantly share code, notes, and snippets.

@kinoshita-lab
Created September 12, 2020 07:27
Show Gist options
  • Save kinoshita-lab/44af5713519b419c132920f1d771694c to your computer and use it in GitHub Desktop.
Save kinoshita-lab/44af5713519b419c132920f1d771694c to your computer and use it in GitHub Desktop.
project euler problem 7
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