Skip to content

Instantly share code, notes, and snippets.

@scratchyone
Created February 2, 2020 04:21
Show Gist options
  • Save scratchyone/8c39cf56120dfa0cd368073d32ac2b65 to your computer and use it in GitHub Desktop.
Save scratchyone/8c39cf56120dfa0cd368073d32ac2b65 to your computer and use it in GitHub Desktop.
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