Skip to content

Instantly share code, notes, and snippets.

@kinoshita-lab
Created September 13, 2020 00:42
Show Gist options
  • Save kinoshita-lab/e4573db0161ad8ff0651deba6c0c2e1f to your computer and use it in GitHub Desktop.
Save kinoshita-lab/e4573db0161ad8ff0651deba6c0c2e1f to your computer and use it in GitHub Desktop.
project euler problem 10
fn is_prime(val: u64) -> bool {
let end = |current_val: u64| -> bool { current_val * current_val > val };
let mut i = 2;
loop {
if end(i) {
return true;
}
if (val % i) == 0 {
return false;
}
i += 1;
}
}
fn main() {
const UPPER: u64 = 2 * 1000000;
let sum: u64 = (2..=UPPER).filter(|i| is_prime(*i as u64)).sum();
println!("{:?}", sum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment