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.180 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.179 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.178 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.177 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.176 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.175 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.174 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.173 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.172 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.171 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.170 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.169 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.167 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.166 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.165 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.164 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.163 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.162 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.161 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.160 tracks/cpp/exercises/sieve/example.cpp