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.2 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.1 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.7.0 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.44 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.43 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.42 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.41 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.40 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.39 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.38 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.37 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.36 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.35 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.34 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.33 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.32 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.31 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.30 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.29 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.6.28 tracks/crystal/exercises/sieve/src/example.cr