Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions nth-prime-solved/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::convert::TryInto;

fn is_prime(nb: u32) -> bool {
if nb == 2 {
return true;
}

for j in 2..nb {
if nb % j == 0 {
return false;
}
}
return true;
}

pub fn nth(n: u32) -> u32 {
let mut primes = Vec::new();

let mut i: u32 = 2;
while primes.len() <= n.try_into().unwrap() {
if is_prime(i) {
primes.push(i);
}
i = i + 1;
}

primes.pop().unwrap()
}
File renamed without changes.
3 changes: 0 additions & 3 deletions nth-prime/src/lib.rs

This file was deleted.