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.43 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.42 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.41 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.40 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.39 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.38 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.37 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.36 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.35 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.34 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.33 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.32 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.31 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.30 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.29 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.28 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.27 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.26 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.24 tracks/crystal/exercises/sieve/src/example.cr
trackler-2.0.8.23 tracks/crystal/exercises/sieve/src/example.cr