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

Version Path
trackler-2.2.1.110 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.109 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.108 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.107 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.106 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.105 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.104 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.103 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.102 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.101 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.100 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.99 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.98 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.97 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.96 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.95 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.94 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.93 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.92 tracks/rust/exercises/nth-prime/example.rs
trackler-2.2.1.91 tracks/rust/exercises/nth-prime/example.rs