Sha256: b604fe9f480042a40d41b14ee2540d593ec81c7df033dbd3cef783089933f426

Contents?: true

Size: 493 Bytes

Versions: 396

Compression:

Stored size: 493 Bytes

Contents

#include "sieve.h"
#include <algorithm>
#include <list>
#include <numeric>

namespace sieve
{

std::vector<int> primes(int n)
{
    std::vector<int> result;
    std::list<int> candidates(n-1);
    std::iota(candidates.begin(), candidates.end(), 2);
    while (!candidates.empty()) {
        const int next = candidates.front();
        candidates.pop_front();
        result.push_back(next);
        candidates.remove_if([next](int n) { return n % next == 0; });
    }
    return result;
}

}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.0.0.5 tracks/cpp/sieve/example.cpp
trackler-2.0.0.4 tracks/cpp/sieve/example.cpp
trackler-2.0.0.3 tracks/cpp/sieve/example.cpp
trackler-2.0.0.2 tracks/cpp/sieve/example.cpp
trackler-2.0.0.1 tracks/cpp/sieve/example.cpp
trackler-2.0.0.0 tracks/cpp/sieve/example.cpp
trackler-1.0.4.1 tracks/cpp/sieve/example.cpp
trackler-1.0.4.0 tracks/cpp/sieve/example.cpp
trackler-1.0.3.0 tracks/cpp/sieve/example.cpp
trackler-1.0.2.1 tracks/cpp/sieve/example.cpp
trackler-1.0.2.0 tracks/cpp/sieve/example.cpp
trackler-1.0.1.2 tracks/cpp/sieve/example.cpp
trackler-1.0.1.1 tracks/cpp/sieve/example.cpp
trackler-1.0.1.0 tracks/cpp/sieve/example.cpp
trackler-1.0.0.1 tracks/cpp/sieve/example.cpp
trackler-1.0.0 tracks/cpp/sieve/example.cpp