Sha256: 48f294f8d0ea741930d1d0a2bdcab9807f4e2d6ffc45f5c9249fa8292649dbaf
Contents?: true
Size: 528 Bytes
Versions: 43
Compression:
Stored size: 528 Bytes
Contents
#!/usr/bin/env ruby # 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
43 entries across 43 versions & 6 rubygems