Created
October 8, 2016 17:37
-
-
Save SCdF/000f3e9a8aeb5ba7aaa380bcf5964cce to your computer and use it in GitHub Desktop.
Hideous knockaround 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
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