Extended maintenance of Ruby versions 1.8.7 and 1.9.2 ended on July 31, 2014. Read more

In Files

  • mathn.rb

Parent

Included Modules

Class/Module Index [+]

Quicksearch

Prime

Public Class Methods

new() click to toggle source
 
               # File mathn.rb, line 72
def initialize
  @seed = 1
  @primes = []
  @counts = []
end
            

Public Instance Methods

each() click to toggle source
 
               # File mathn.rb, line 102
def each
  loop do
    yield succ
  end
end
            
next() click to toggle source
Alias for: succ
succ() click to toggle source
 
               # File mathn.rb, line 78
def succ
  i = -1
  size = @primes.size
  while i < size
    if i == -1
      @seed += 1
      i += 1
    else
      while @seed > @counts[i]
        @counts[i] += @primes[i]
      end
      if @seed != @counts[i]
        i += 1
      else
        i = -1
      end
    end
  end
  @primes.push @seed
  @counts.push @seed + @seed
  return @seed
end
            
Also aliased as: next