Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end 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

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus