Sha256: d22cd66126333ac809d92b763720b5b06b9e8b624840d3729e9cb7bb32158bcf
Contents?: true
Size: 573 Bytes
Versions: 104
Compression:
Stored size: 573 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) -> Result<u32, ()> { match n { 0 => Err(()), 1 => Ok(2), _ => { let mut count: u32 = 1; let mut candidate: u32 = 1; while count < n { candidate += 2; if is_prime(candidate) { count += 1; } } Ok(candidate) } } }
Version data entries
104 entries across 104 versions & 1 rubygems