Skip to content

Instantly share code, notes, and snippets.

@selfup
Created May 22, 2016 23:12
Show Gist options
  • Save selfup/2015ec3c910413c03e337154b88d7b66 to your computer and use it in GitHub Desktop.
Save selfup/2015ec3c910413c03e337154b88d7b66 to your computer and use it in GitHub Desktop.
#[no_mangle]
pub extern fn nth_prime(num: u32) -> u32 {
let mut i = 0;
let mut count = 0;
while count <= num {
i += 1;
if prime(i) {
count += 1;
}
}
i
}
fn prime(num: u32) -> bool {
let mut i = 2;
while i < num {
if num % i == 0 {
return false;
}
i += 1;
}
true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment