Created
February 2, 2020 04:21
-
-
Save scratchyone/8c39cf56120dfa0cd368073d32ac2b65 to your computer and use it in GitHub Desktop.
This file contains 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
pub fn prime(amount: i32) -> Vec<i64> { | |
let amount: usize = amount as usize; | |
let mut out: Vec<usize> = (0..amount) | |
.map(|n| { | |
if n % 2 == 1 && n % 5 != 0 && n % 3 != 0 && n % 7 != 0 { | |
n | |
} else { | |
0 | |
} | |
}) | |
.collect::<Vec<usize>>(); | |
for x in 2..amount { | |
if out[x] == 0 { | |
continue; | |
} | |
for i in (x * x..amount).step_by(x) { | |
{ | |
out[i] = 0; | |
} | |
} | |
} | |
return out | |
.into_iter() | |
.filter(|n| *n != 0) | |
.map(|n| n as i64) | |
.collect::<Vec<i64>>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment