Skip to content

Instantly share code, notes, and snippets.

@scratchyone
Created February 2, 2020 03:39
Show Gist options
  • Save scratchyone/c43486b0a8377e4f3af2cb221d1cccbc to your computer and use it in GitHub Desktop.
Save scratchyone/c43486b0a8377e4f3af2cb221d1cccbc 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).collect::<Vec<usize>>();
for x in 2..amount {
for i in (x * x..amount).step_by(x) {
out[i] = 0;
}
if out[x] == 0 {
continue;
}
}
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