Last active
April 7, 2016 06:35
-
-
Save NecroTechno/d57da4a87f8cdd01b155 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
#![feature(collections)] | |
fn sieve_controller(limit: i32) { | |
let limitn = limit + 1; | |
let mut primes: Vec<i32> = Vec::new(); | |
let mut factors: Vec<i32> = Vec::new(); | |
let mut counter: Vec<i32> = Vec::new(); | |
for i in 2..limitn { | |
primes.push(i); | |
} | |
for &i in &primes { | |
let mut s = i; | |
while s < limitn { | |
factors.push(s); | |
counter.push(s); | |
s += i; | |
} | |
} | |
fn prime_sieve(primes: Vec<i32>, factors: Vec<i32>, counter: Vec<i32>) { | |
let mut list1 = primes; | |
let list2 = factors; | |
let list3 = counter; | |
for f in list3 { | |
let rm = list1.position_elem(&f); | |
list1.remove(rm.unwrap()); | |
} | |
for x in list1 { | |
println!("{}", x); | |
} | |
} | |
prime_sieve(primes, factors, counter); | |
} | |
fn main() { | |
sieve_controller(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment