aboutsummaryrefslogtreecommitdiff
path: root/rust/nth-prime/src
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2020-12-26 17:48:38 +0000
committerFederico Igne <git@federicoigne.com>2021-11-03 18:55:08 +0000
commit02481656966b0a8dfc95cf3c22bcc049660ff7d4 (patch)
tree8e39798fcaf27931d91c2088423fd4e97adcfc2d /rust/nth-prime/src
parent4e2052c4d792540c2f742b2c2a081b11117ed41d (diff)
downloadexercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.tar.gz
exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.zip
Move Rust exercises in a subdirectory
Diffstat (limited to 'rust/nth-prime/src')
-rw-r--r--rust/nth-prime/src/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/rust/nth-prime/src/lib.rs b/rust/nth-prime/src/lib.rs
new file mode 100644
index 0000000..ef9d7ea
--- /dev/null
+++ b/rust/nth-prime/src/lib.rs
@@ -0,0 +1,8 @@
1fn is_prime(n: u32) -> bool {
2 let limit = (n as f64).sqrt() as u32;
3 (2..=limit).all(|x| n % x != 0)
4}
5
6pub fn nth(n: u32) -> u32 {
7 (2..).filter(|x| is_prime(*x)).nth(n as usize).unwrap()
8}