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.2.1.159 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.158 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.157 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.156 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.155 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.154 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.153 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.152 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.151 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.150 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.149 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.148 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.147 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.146 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.145 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.144 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.143 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.142 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.141 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.140 tracks/cpp/exercises/sieve/example.cpp