Class: Prime
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize ⇒ Prime
constructor
A new instance of Prime.
- #succ ⇒ Object (also: #next)
Constructor Details
#initialize ⇒ Prime
Returns a new instance of Prime.
77 78 79 80 81 |
# File 'lib/rubysl/mathn/mathn.rb', line 77 def initialize @seed = 1 @primes = [] @counts = [] end |
Instance Method Details
#each ⇒ Object
107 108 109 110 111 |
# File 'lib/rubysl/mathn/mathn.rb', line 107 def each loop do yield succ end end |
#succ ⇒ Object Also known as: next
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rubysl/mathn/mathn.rb', line 83 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 |