Skip to content

Instantly share code, notes, and snippets.

@SCdF
Created October 8, 2016 17:37
Show Gist options
  • Save SCdF/000f3e9a8aeb5ba7aaa380bcf5964cce to your computer and use it in GitHub Desktop.
Save SCdF/000f3e9a8aeb5ba7aaa380bcf5964cce to your computer and use it in GitHub Desktop.
Hideous knockaround in rust
fn next_prime(given: &Vec<i32>) -> Option<i32> {
fn is_prime(given: &Vec<i32>, i: i32) -> bool {
given.iter().all(|&x| i % x != 0)
}
if let Some(next) = given.iter().last() {
let mut next = next + 1;
while !is_prime(given, next) {
next += 1;
}
Some(next)
} else {
None
}
}
fn main() {
let mut primes = vec![2];
for _ in 1..1000 {
let np = next_prime(&primes);
if let Some(np) = np {
primes.push(np);
}
}
println!("one obviously well and {:?}", primes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment