Created
May 22, 2016 23:12
-
-
Save selfup/2015ec3c910413c03e337154b88d7b66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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