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.139 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.138 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.137 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.136 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.135 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.134 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.133 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.132 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.131 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.130 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.129 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.128 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.127 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.126 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.125 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.124 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.123 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.122 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.121 tracks/cpp/exercises/sieve/example.cpp
trackler-2.2.1.120 tracks/cpp/exercises/sieve/example.cpp