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

Version Path
solidus_backend-1.0.0.pre3 vendor/bundle/gems/byebug-2.7.0/test/examples/primes.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/byebug-2.7.0/test/examples/primes.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/byebug-2.7.0/test/examples/primes.rb
byebug-3.0.0 test/examples/primes.rb
byebug-2.7.0 test/examples/primes.rb
byebug-2.6.0 test/examples/primes.rb
byebug-2.5.0 test/examples/primes.rb
byebug-2.4.1 test/examples/primes.rb
byebug-2.4.0 test/examples/primes.rb
byebug-2.3.1 test/examples/primes.rb
byebug-2.3.0 test/examples/primes.rb
byebug-2.2.2 old_doc/primes.rb
byebug-2.2.1 old_doc/primes.rb
byebug-2.2.0 old_doc/primes.rb
byebug-2.1.1 old_doc/primes.rb
byebug-2.1.0 old_doc/primes.rb
byebug-2.0.0 old_doc/primes.rb
byebug-1.8.2 old_doc/primes.rb
byebug-1.8.1 old_doc/primes.rb
byebug-1.8.0 old_doc/primes.rb