Sha256: d6733905bfd9072f41edf97fc6950662ac3daf600c957629dbb500b10081032f

Contents?: true

Size: 679 Bytes

Versions: 63

Compression:

Stored size: 679 Bytes

Contents

import ceylon.numeric.float {
    sqrt
}

{Integer*} primesUpTo(Integer max) {
    // if max < 4, sqrt(max) < 2, so 2..sqrt(max) gives decreasing values.
    // Prevent this by just returning the small primes here:
    if (max < 4) {
        return { 2, 3 }.takeWhile((c) => c <= max);
    }
    
    value prime = Array.ofSize(max + 1, true);
    prime[0] = false;
    prime[1] = false;
    
    for (i in 2 .. (sqrt(max.float).integer)) {
        if (!(prime[i] else false)) {
            continue;
        }
        
        for (multiple in ((i * i) .. max).by(i)) {
            prime[multiple] = false;
        }
    }
    return { for (i->p in prime.indexed) if (p) i };
}

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.179 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.178 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.177 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.176 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.175 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.174 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.173 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.172 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.171 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.170 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.169 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.167 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.166 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.165 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.164 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.163 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.162 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.161 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.160 tracks/ceylon/exercises/sieve/example/Sieve.ceylon