Sha256: 6341779a58ef36d591a0156c1cea362258c2d9fe14455a6f469b3057b769adc0
Contents?: true
Size: 570 Bytes
Versions: 67
Compression:
Stored size: 570 Bytes
Contents
fn is_prime(n: u32) -> bool { let mut i: u32 = 3; while (i * i) < (n + 1) { if n % i == 0 { return false; } i += 1; } return true; } pub fn nth(n: u32) -> Option<u32> { match n { 0 => None, 1 => Some(2), _ => { let mut count: u32 = 1; let mut candidate: u32 = 1; while count < n { candidate += 2; if is_prime(candidate) { count += 1; } } Some(candidate) } } }
Version data entries
67 entries across 67 versions & 1 rubygems