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