Sha256: f1e444d3ec5a0c37ff73d6fe5269b7c5e7f9fb6d66ae70ddf21bd2b61eeecde5
Contents?: true
Size: 501 Bytes
Versions: 28
Compression:
Stored size: 501 Bytes
Contents
# Enumerator for primes class SievePrime @@odd_primes = [] def self.next_prime(&block) candidate = 2 yield candidate not_prime = false candidate += 1 while true do @@odd_primes.each do |p| not_prime = (0 == (candidate % p)) break if not_prime end unless not_prime @@odd_primes << candidate yield candidate end candidate += 2 end end end SievePrime.next_prime do |prime| puts prime break if prime > 10 end
Version data entries
28 entries across 28 versions & 2 rubygems