Sha256: 837a799aa5014b42c1b2b4f76fbfd3a38111b9842141542951c5d197ee3bf0ff

Contents?: true

Size: 603 Bytes

Versions: 267

Compression:

Stored size: 603 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

267 entries across 267 versions & 1 rubygems

Version Path
trackler-2.2.1.116 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.115 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.114 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.113 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.111 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.110 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.109 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.108 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.107 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.106 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.105 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.104 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.103 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.102 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.101 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.100 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.99 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.98 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.97 tracks/ceylon/exercises/sieve/example/Sieve.ceylon
trackler-2.2.1.96 tracks/ceylon/exercises/sieve/example/Sieve.ceylon