DEV Community

Discussion on: The Sieve of Eratosthenes

Collapse
chenge profile image
chenge
pub fn primes_up_to(limit: u32) -> Vec<u32> {
    let mut primes = Vec::new();
    let mut candidates: Vec<_> = (2..=limit).rev().collect();
    while let Some(prime) = candidates.pop() {
        primes.push(prime);
        candidates.retain(|n| n % prime != 0);
    }
    primes
}
Enter fullscreen mode Exit fullscreen mode
Collapse
nickymeuleman profile image
Nicky Meuleman Author

Very nicely done!

Collapse
chenge profile image
chenge

I found this at exercism.io. A good site for learning.

Thread Thread
nickymeuleman profile image
Nicky Meuleman Author

I really enjoy that site!
Going through all exercises in the Rust track.
I have my solutions opensourced on github github.com/NickyMeuleman/scrapyard...