Skip to content

Instantly share code, notes, and snippets.

@ikzekly
Created May 20, 2018 21:44
Show Gist options
  • Save ikzekly/6d4bfd93e1a8ad745d0ab4b444ef71da to your computer and use it in GitHub Desktop.
Save ikzekly/6d4bfd93e1a8ad745d0ab4b444ef71da to your computer and use it in GitHub Desktop.
pub fn nth(n: u32) -> Option<u32> {
pub fn is_prime(n: u32) -> bool {
if n == 1 {return false};
if n == 2 {return true};
let sqrt_n = ((n as f32).sqrt() as u32) + 1;
for i in 2..sqrt_n {
if n % i == 0 {return false};
}
true
}
let mut primes = Vec::new();
while primes.len() < n as usize {
for n in 0..100000000 {
if is_prime(n) { primes.push(n); }
}
}
Some(primes[n as usize +1])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment