Sha256: c19d5199d41c3ed55b667186684a106444194f611d9004e856712ce64094e17f

Contents?: true

Size: 350 Bytes

Versions: 143

Compression:

Stored size: 350 Bytes

Contents

module Primes
  extend self

  def sieve(limit)
    sieve_ar = Array.new(limit + 1, true)
    sieve_ar[0] = sieve_ar[1] = false
    2.step(Math.sqrt(limit)) do |i|
      next unless sieve_ar[i]
      (i*i).step(limit, i) { |ii| sieve_ar[ii] = false }
    end

    sieve_ar.each_with_index.reduce([] of Int32) { |p, (s, i)| s ? p << i : p }
  end
end

Version data entries

143 entries across 143 versions & 1 rubygems

Version Path
trackler-2.0.8.22 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.21 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.20 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.19 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.18 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.17 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.16 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.15 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.14 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.13 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.12 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.11 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.10 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.9 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.8 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.7 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.6 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.5 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.4 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.3 tracks/crystal/exercises/sieve/src/example.cr