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