Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/ruby22/lib64/ruby/2.2.0
File: prime.rb
#
[0] Fix | Delete
# = prime.rb
[1] Fix | Delete
#
[2] Fix | Delete
# Prime numbers and factorization library.
[3] Fix | Delete
#
[4] Fix | Delete
# Copyright::
[5] Fix | Delete
# Copyright (c) 1998-2008 Keiju ISHITSUKA(SHL Japan Inc.)
[6] Fix | Delete
# Copyright (c) 2008 Yuki Sonoda (Yugui) <yugui@yugui.jp>
[7] Fix | Delete
#
[8] Fix | Delete
# Documentation::
[9] Fix | Delete
# Yuki Sonoda
[10] Fix | Delete
#
[11] Fix | Delete
[12] Fix | Delete
require "singleton"
[13] Fix | Delete
require "forwardable"
[14] Fix | Delete
[15] Fix | Delete
class Integer
[16] Fix | Delete
# Re-composes a prime factorization and returns the product.
[17] Fix | Delete
#
[18] Fix | Delete
# See Prime#int_from_prime_division for more details.
[19] Fix | Delete
def Integer.from_prime_division(pd)
[20] Fix | Delete
Prime.int_from_prime_division(pd)
[21] Fix | Delete
end
[22] Fix | Delete
[23] Fix | Delete
# Returns the factorization of +self+.
[24] Fix | Delete
#
[25] Fix | Delete
# See Prime#prime_division for more details.
[26] Fix | Delete
def prime_division(generator = Prime::Generator23.new)
[27] Fix | Delete
Prime.prime_division(self, generator)
[28] Fix | Delete
end
[29] Fix | Delete
[30] Fix | Delete
# Returns true if +self+ is a prime number, else returns false.
[31] Fix | Delete
def prime?
[32] Fix | Delete
Prime.prime?(self)
[33] Fix | Delete
end
[34] Fix | Delete
[35] Fix | Delete
# Iterates the given block over all prime numbers.
[36] Fix | Delete
#
[37] Fix | Delete
# See +Prime+#each for more details.
[38] Fix | Delete
def Integer.each_prime(ubound, &block) # :yields: prime
[39] Fix | Delete
Prime.each(ubound, &block)
[40] Fix | Delete
end
[41] Fix | Delete
end
[42] Fix | Delete
[43] Fix | Delete
#
[44] Fix | Delete
# The set of all prime numbers.
[45] Fix | Delete
#
[46] Fix | Delete
# == Example
[47] Fix | Delete
#
[48] Fix | Delete
# Prime.each(100) do |prime|
[49] Fix | Delete
# p prime #=> 2, 3, 5, 7, 11, ...., 97
[50] Fix | Delete
# end
[51] Fix | Delete
#
[52] Fix | Delete
# Prime is Enumerable:
[53] Fix | Delete
#
[54] Fix | Delete
# Prime.first 5 # => [2, 3, 5, 7, 11]
[55] Fix | Delete
#
[56] Fix | Delete
# == Retrieving the instance
[57] Fix | Delete
#
[58] Fix | Delete
# +Prime+.new is obsolete. Now +Prime+ has the default instance and you can
[59] Fix | Delete
# access it as +Prime+.instance.
[60] Fix | Delete
#
[61] Fix | Delete
# For convenience, each instance method of +Prime+.instance can be accessed
[62] Fix | Delete
# as a class method of +Prime+.
[63] Fix | Delete
#
[64] Fix | Delete
# e.g.
[65] Fix | Delete
# Prime.instance.prime?(2) #=> true
[66] Fix | Delete
# Prime.prime?(2) #=> true
[67] Fix | Delete
#
[68] Fix | Delete
# == Generators
[69] Fix | Delete
#
[70] Fix | Delete
# A "generator" provides an implementation of enumerating pseudo-prime
[71] Fix | Delete
# numbers and it remembers the position of enumeration and upper bound.
[72] Fix | Delete
# Furthermore, it is an external iterator of prime enumeration which is
[73] Fix | Delete
# compatible with an Enumerator.
[74] Fix | Delete
#
[75] Fix | Delete
# +Prime+::+PseudoPrimeGenerator+ is the base class for generators.
[76] Fix | Delete
# There are few implementations of generator.
[77] Fix | Delete
#
[78] Fix | Delete
# [+Prime+::+EratosthenesGenerator+]
[79] Fix | Delete
# Uses eratosthenes' sieve.
[80] Fix | Delete
# [+Prime+::+TrialDivisionGenerator+]
[81] Fix | Delete
# Uses the trial division method.
[82] Fix | Delete
# [+Prime+::+Generator23+]
[83] Fix | Delete
# Generates all positive integers which are not divisible by either 2 or 3.
[84] Fix | Delete
# This sequence is very bad as a pseudo-prime sequence. But this
[85] Fix | Delete
# is faster and uses much less memory than the other generators. So,
[86] Fix | Delete
# it is suitable for factorizing an integer which is not large but
[87] Fix | Delete
# has many prime factors. e.g. for Prime#prime? .
[88] Fix | Delete
[89] Fix | Delete
class Prime
[90] Fix | Delete
include Enumerable
[91] Fix | Delete
@the_instance = Prime.new
[92] Fix | Delete
[93] Fix | Delete
# obsolete. Use +Prime+::+instance+ or class methods of +Prime+.
[94] Fix | Delete
def initialize
[95] Fix | Delete
@generator = EratosthenesGenerator.new
[96] Fix | Delete
extend OldCompatibility
[97] Fix | Delete
warn "Prime::new is obsolete. use Prime::instance or class methods of Prime."
[98] Fix | Delete
end
[99] Fix | Delete
[100] Fix | Delete
class << self
[101] Fix | Delete
extend Forwardable
[102] Fix | Delete
include Enumerable
[103] Fix | Delete
# Returns the default instance of Prime.
[104] Fix | Delete
def instance; @the_instance end
[105] Fix | Delete
[106] Fix | Delete
def method_added(method) # :nodoc:
[107] Fix | Delete
(class<< self;self;end).def_delegator :instance, method
[108] Fix | Delete
end
[109] Fix | Delete
end
[110] Fix | Delete
[111] Fix | Delete
# Iterates the given block over all prime numbers.
[112] Fix | Delete
#
[113] Fix | Delete
# == Parameters
[114] Fix | Delete
#
[115] Fix | Delete
# +ubound+::
[116] Fix | Delete
# Optional. An arbitrary positive number.
[117] Fix | Delete
# The upper bound of enumeration. The method enumerates
[118] Fix | Delete
# prime numbers infinitely if +ubound+ is nil.
[119] Fix | Delete
# +generator+::
[120] Fix | Delete
# Optional. An implementation of pseudo-prime generator.
[121] Fix | Delete
#
[122] Fix | Delete
# == Return value
[123] Fix | Delete
#
[124] Fix | Delete
# An evaluated value of the given block at the last time.
[125] Fix | Delete
# Or an enumerator which is compatible to an +Enumerator+
[126] Fix | Delete
# if no block given.
[127] Fix | Delete
#
[128] Fix | Delete
# == Description
[129] Fix | Delete
#
[130] Fix | Delete
# Calls +block+ once for each prime number, passing the prime as
[131] Fix | Delete
# a parameter.
[132] Fix | Delete
#
[133] Fix | Delete
# +ubound+::
[134] Fix | Delete
# Upper bound of prime numbers. The iterator stops after it
[135] Fix | Delete
# yields all prime numbers p <= +ubound+.
[136] Fix | Delete
#
[137] Fix | Delete
# == Note
[138] Fix | Delete
#
[139] Fix | Delete
# +Prime+.+new+ returns an object extended by +Prime+::+OldCompatibility+
[140] Fix | Delete
# in order to be compatible with Ruby 1.8, and +Prime+#each is overwritten
[141] Fix | Delete
# by +Prime+::+OldCompatibility+#+each+.
[142] Fix | Delete
#
[143] Fix | Delete
# +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
[144] Fix | Delete
# +Prime+.+each+.
[145] Fix | Delete
def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
[146] Fix | Delete
generator.upper_bound = ubound
[147] Fix | Delete
generator.each(&block)
[148] Fix | Delete
end
[149] Fix | Delete
[150] Fix | Delete
[151] Fix | Delete
# Returns true if +value+ is a prime number, else returns false.
[152] Fix | Delete
#
[153] Fix | Delete
# == Parameters
[154] Fix | Delete
#
[155] Fix | Delete
# +value+:: an arbitrary integer to be checked.
[156] Fix | Delete
# +generator+:: optional. A pseudo-prime generator.
[157] Fix | Delete
def prime?(value, generator = Prime::Generator23.new)
[158] Fix | Delete
return false if value < 2
[159] Fix | Delete
for num in generator
[160] Fix | Delete
q,r = value.divmod num
[161] Fix | Delete
return true if q < num
[162] Fix | Delete
return false if r == 0
[163] Fix | Delete
end
[164] Fix | Delete
end
[165] Fix | Delete
[166] Fix | Delete
# Re-composes a prime factorization and returns the product.
[167] Fix | Delete
#
[168] Fix | Delete
# == Parameters
[169] Fix | Delete
# +pd+:: Array of pairs of integers. The each internal
[170] Fix | Delete
# pair consists of a prime number -- a prime factor --
[171] Fix | Delete
# and a natural number -- an exponent.
[172] Fix | Delete
#
[173] Fix | Delete
# == Example
[174] Fix | Delete
# For <tt>[[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]]</tt>, it returns:
[175] Fix | Delete
#
[176] Fix | Delete
# p_1**e_1 * p_2**e_2 * .... * p_n**e_n.
[177] Fix | Delete
#
[178] Fix | Delete
# Prime.int_from_prime_division([[2,2], [3,1]]) #=> 12
[179] Fix | Delete
def int_from_prime_division(pd)
[180] Fix | Delete
pd.inject(1){|value, (prime, index)|
[181] Fix | Delete
value * prime**index
[182] Fix | Delete
}
[183] Fix | Delete
end
[184] Fix | Delete
[185] Fix | Delete
# Returns the factorization of +value+.
[186] Fix | Delete
#
[187] Fix | Delete
# == Parameters
[188] Fix | Delete
# +value+:: An arbitrary integer.
[189] Fix | Delete
# +generator+:: Optional. A pseudo-prime generator.
[190] Fix | Delete
# +generator+.succ must return the next
[191] Fix | Delete
# pseudo-prime number in the ascending
[192] Fix | Delete
# order. It must generate all prime numbers,
[193] Fix | Delete
# but may also generate non prime numbers too.
[194] Fix | Delete
#
[195] Fix | Delete
# === Exceptions
[196] Fix | Delete
# +ZeroDivisionError+:: when +value+ is zero.
[197] Fix | Delete
#
[198] Fix | Delete
# == Example
[199] Fix | Delete
# For an arbitrary integer:
[200] Fix | Delete
#
[201] Fix | Delete
# n = p_1**e_1 * p_2**e_2 * .... * p_n**e_n,
[202] Fix | Delete
#
[203] Fix | Delete
# prime_division(n) returns:
[204] Fix | Delete
#
[205] Fix | Delete
# [[p_1, e_1], [p_2, e_2], ...., [p_n, e_n]].
[206] Fix | Delete
#
[207] Fix | Delete
# Prime.prime_division(12) #=> [[2,2], [3,1]]
[208] Fix | Delete
#
[209] Fix | Delete
def prime_division(value, generator = Prime::Generator23.new)
[210] Fix | Delete
raise ZeroDivisionError if value == 0
[211] Fix | Delete
if value < 0
[212] Fix | Delete
value = -value
[213] Fix | Delete
pv = [[-1, 1]]
[214] Fix | Delete
else
[215] Fix | Delete
pv = []
[216] Fix | Delete
end
[217] Fix | Delete
for prime in generator
[218] Fix | Delete
count = 0
[219] Fix | Delete
while (value1, mod = value.divmod(prime)
[220] Fix | Delete
mod) == 0
[221] Fix | Delete
value = value1
[222] Fix | Delete
count += 1
[223] Fix | Delete
end
[224] Fix | Delete
if count != 0
[225] Fix | Delete
pv.push [prime, count]
[226] Fix | Delete
end
[227] Fix | Delete
break if value1 <= prime
[228] Fix | Delete
end
[229] Fix | Delete
if value > 1
[230] Fix | Delete
pv.push [value, 1]
[231] Fix | Delete
end
[232] Fix | Delete
return pv
[233] Fix | Delete
end
[234] Fix | Delete
[235] Fix | Delete
# An abstract class for enumerating pseudo-prime numbers.
[236] Fix | Delete
#
[237] Fix | Delete
# Concrete subclasses should override succ, next, rewind.
[238] Fix | Delete
class PseudoPrimeGenerator
[239] Fix | Delete
include Enumerable
[240] Fix | Delete
[241] Fix | Delete
def initialize(ubound = nil)
[242] Fix | Delete
@ubound = ubound
[243] Fix | Delete
end
[244] Fix | Delete
[245] Fix | Delete
def upper_bound=(ubound)
[246] Fix | Delete
@ubound = ubound
[247] Fix | Delete
end
[248] Fix | Delete
def upper_bound
[249] Fix | Delete
@ubound
[250] Fix | Delete
end
[251] Fix | Delete
[252] Fix | Delete
# returns the next pseudo-prime number, and move the internal
[253] Fix | Delete
# position forward.
[254] Fix | Delete
#
[255] Fix | Delete
# +PseudoPrimeGenerator+#succ raises +NotImplementedError+.
[256] Fix | Delete
def succ
[257] Fix | Delete
raise NotImplementedError, "need to define `succ'"
[258] Fix | Delete
end
[259] Fix | Delete
[260] Fix | Delete
# alias of +succ+.
[261] Fix | Delete
def next
[262] Fix | Delete
raise NotImplementedError, "need to define `next'"
[263] Fix | Delete
end
[264] Fix | Delete
[265] Fix | Delete
# Rewinds the internal position for enumeration.
[266] Fix | Delete
#
[267] Fix | Delete
# See +Enumerator+#rewind.
[268] Fix | Delete
def rewind
[269] Fix | Delete
raise NotImplementedError, "need to define `rewind'"
[270] Fix | Delete
end
[271] Fix | Delete
[272] Fix | Delete
# Iterates the given block for each prime number.
[273] Fix | Delete
def each
[274] Fix | Delete
return self.dup unless block_given?
[275] Fix | Delete
if @ubound
[276] Fix | Delete
last_value = nil
[277] Fix | Delete
loop do
[278] Fix | Delete
prime = succ
[279] Fix | Delete
break last_value if prime > @ubound
[280] Fix | Delete
last_value = yield prime
[281] Fix | Delete
end
[282] Fix | Delete
else
[283] Fix | Delete
loop do
[284] Fix | Delete
yield succ
[285] Fix | Delete
end
[286] Fix | Delete
end
[287] Fix | Delete
end
[288] Fix | Delete
[289] Fix | Delete
# see +Enumerator+#with_index.
[290] Fix | Delete
alias with_index each_with_index
[291] Fix | Delete
[292] Fix | Delete
# see +Enumerator+#with_object.
[293] Fix | Delete
def with_object(obj)
[294] Fix | Delete
return enum_for(:with_object) unless block_given?
[295] Fix | Delete
each do |prime|
[296] Fix | Delete
yield prime, obj
[297] Fix | Delete
end
[298] Fix | Delete
end
[299] Fix | Delete
end
[300] Fix | Delete
[301] Fix | Delete
# An implementation of +PseudoPrimeGenerator+.
[302] Fix | Delete
#
[303] Fix | Delete
# Uses +EratosthenesSieve+.
[304] Fix | Delete
class EratosthenesGenerator < PseudoPrimeGenerator
[305] Fix | Delete
def initialize
[306] Fix | Delete
@last_prime_index = -1
[307] Fix | Delete
super
[308] Fix | Delete
end
[309] Fix | Delete
[310] Fix | Delete
def succ
[311] Fix | Delete
@last_prime_index += 1
[312] Fix | Delete
EratosthenesSieve.instance.get_nth_prime(@last_prime_index)
[313] Fix | Delete
end
[314] Fix | Delete
def rewind
[315] Fix | Delete
initialize
[316] Fix | Delete
end
[317] Fix | Delete
alias next succ
[318] Fix | Delete
end
[319] Fix | Delete
[320] Fix | Delete
# An implementation of +PseudoPrimeGenerator+ which uses
[321] Fix | Delete
# a prime table generated by trial division.
[322] Fix | Delete
class TrialDivisionGenerator<PseudoPrimeGenerator
[323] Fix | Delete
def initialize
[324] Fix | Delete
@index = -1
[325] Fix | Delete
super
[326] Fix | Delete
end
[327] Fix | Delete
[328] Fix | Delete
def succ
[329] Fix | Delete
TrialDivision.instance[@index += 1]
[330] Fix | Delete
end
[331] Fix | Delete
def rewind
[332] Fix | Delete
initialize
[333] Fix | Delete
end
[334] Fix | Delete
alias next succ
[335] Fix | Delete
end
[336] Fix | Delete
[337] Fix | Delete
# Generates all integers which are greater than 2 and
[338] Fix | Delete
# are not divisible by either 2 or 3.
[339] Fix | Delete
#
[340] Fix | Delete
# This is a pseudo-prime generator, suitable on
[341] Fix | Delete
# checking primality of an integer by brute force
[342] Fix | Delete
# method.
[343] Fix | Delete
class Generator23<PseudoPrimeGenerator
[344] Fix | Delete
def initialize
[345] Fix | Delete
@prime = 1
[346] Fix | Delete
@step = nil
[347] Fix | Delete
super
[348] Fix | Delete
end
[349] Fix | Delete
[350] Fix | Delete
def succ
[351] Fix | Delete
if (@step)
[352] Fix | Delete
@prime += @step
[353] Fix | Delete
@step = 6 - @step
[354] Fix | Delete
else
[355] Fix | Delete
case @prime
[356] Fix | Delete
when 1; @prime = 2
[357] Fix | Delete
when 2; @prime = 3
[358] Fix | Delete
when 3; @prime = 5; @step = 2
[359] Fix | Delete
end
[360] Fix | Delete
end
[361] Fix | Delete
return @prime
[362] Fix | Delete
end
[363] Fix | Delete
alias next succ
[364] Fix | Delete
def rewind
[365] Fix | Delete
initialize
[366] Fix | Delete
end
[367] Fix | Delete
end
[368] Fix | Delete
[369] Fix | Delete
# Internal use. An implementation of prime table by trial division method.
[370] Fix | Delete
class TrialDivision
[371] Fix | Delete
include Singleton
[372] Fix | Delete
[373] Fix | Delete
def initialize # :nodoc:
[374] Fix | Delete
# These are included as class variables to cache them for later uses. If memory
[375] Fix | Delete
# usage is a problem, they can be put in Prime#initialize as instance variables.
[376] Fix | Delete
[377] Fix | Delete
# There must be no primes between @primes[-1] and @next_to_check.
[378] Fix | Delete
@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
[379] Fix | Delete
# @next_to_check % 6 must be 1.
[380] Fix | Delete
@next_to_check = 103 # @primes[-1] - @primes[-1] % 6 + 7
[381] Fix | Delete
@ulticheck_index = 3 # @primes.index(@primes.reverse.find {|n|
[382] Fix | Delete
# n < Math.sqrt(@@next_to_check) })
[383] Fix | Delete
@ulticheck_next_squared = 121 # @primes[@ulticheck_index + 1] ** 2
[384] Fix | Delete
end
[385] Fix | Delete
[386] Fix | Delete
# Returns the cached prime numbers.
[387] Fix | Delete
def cache
[388] Fix | Delete
return @primes
[389] Fix | Delete
end
[390] Fix | Delete
alias primes cache
[391] Fix | Delete
alias primes_so_far cache
[392] Fix | Delete
[393] Fix | Delete
# Returns the +index+th prime number.
[394] Fix | Delete
#
[395] Fix | Delete
# +index+ is a 0-based index.
[396] Fix | Delete
def [](index)
[397] Fix | Delete
while index >= @primes.length
[398] Fix | Delete
# Only check for prime factors up to the square root of the potential primes,
[399] Fix | Delete
# but without the performance hit of an actual square root calculation.
[400] Fix | Delete
if @next_to_check + 4 > @ulticheck_next_squared
[401] Fix | Delete
@ulticheck_index += 1
[402] Fix | Delete
@ulticheck_next_squared = @primes.at(@ulticheck_index + 1) ** 2
[403] Fix | Delete
end
[404] Fix | Delete
# Only check numbers congruent to one and five, modulo six. All others
[405] Fix | Delete
[406] Fix | Delete
# are divisible by two or three. This also allows us to skip checking against
[407] Fix | Delete
# two and three.
[408] Fix | Delete
@primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
[409] Fix | Delete
@next_to_check += 4
[410] Fix | Delete
@primes.push @next_to_check if @primes[2..@ulticheck_index].find {|prime| @next_to_check % prime == 0 }.nil?
[411] Fix | Delete
@next_to_check += 2
[412] Fix | Delete
end
[413] Fix | Delete
return @primes[index]
[414] Fix | Delete
end
[415] Fix | Delete
end
[416] Fix | Delete
[417] Fix | Delete
# Internal use. An implementation of eratosthenes' sieve
[418] Fix | Delete
class EratosthenesSieve
[419] Fix | Delete
include Singleton
[420] Fix | Delete
[421] Fix | Delete
def initialize
[422] Fix | Delete
@primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
[423] Fix | Delete
# @max_checked must be an even number
[424] Fix | Delete
@max_checked = @primes.last + 1
[425] Fix | Delete
end
[426] Fix | Delete
[427] Fix | Delete
def get_nth_prime(n)
[428] Fix | Delete
compute_primes while @primes.size <= n
[429] Fix | Delete
@primes[n]
[430] Fix | Delete
end
[431] Fix | Delete
[432] Fix | Delete
private
[433] Fix | Delete
def compute_primes
[434] Fix | Delete
# max_segment_size must be an even number
[435] Fix | Delete
max_segment_size = 1e6.to_i
[436] Fix | Delete
max_cached_prime = @primes.last
[437] Fix | Delete
# do not double count primes if #compute_primes is interrupted
[438] Fix | Delete
# by Timeout.timeout
[439] Fix | Delete
@max_checked = max_cached_prime + 1 if max_cached_prime > @max_checked
[440] Fix | Delete
[441] Fix | Delete
segment_min = @max_checked
[442] Fix | Delete
segment_max = [segment_min + max_segment_size, max_cached_prime * 2].min
[443] Fix | Delete
root = Integer(Math.sqrt(segment_max).floor)
[444] Fix | Delete
[445] Fix | Delete
sieving_primes = @primes[1 .. -1].take_while { |prime| prime <= root }
[446] Fix | Delete
offsets = Array.new(sieving_primes.size) do |i|
[447] Fix | Delete
(-(segment_min + 1 + sieving_primes[i]) / 2) % sieving_primes[i]
[448] Fix | Delete
end
[449] Fix | Delete
[450] Fix | Delete
segment = ((segment_min + 1) .. segment_max).step(2).to_a
[451] Fix | Delete
sieving_primes.each_with_index do |prime, index|
[452] Fix | Delete
composite_index = offsets[index]
[453] Fix | Delete
while composite_index < segment.size do
[454] Fix | Delete
segment[composite_index] = nil
[455] Fix | Delete
composite_index += prime
[456] Fix | Delete
end
[457] Fix | Delete
end
[458] Fix | Delete
[459] Fix | Delete
segment.each do |prime|
[460] Fix | Delete
@primes.push prime unless prime.nil?
[461] Fix | Delete
end
[462] Fix | Delete
@max_checked = segment_max
[463] Fix | Delete
end
[464] Fix | Delete
end
[465] Fix | Delete
[466] Fix | Delete
# Provides a +Prime+ object with compatibility to Ruby 1.8 when instantiated via +Prime+.+new+.
[467] Fix | Delete
module OldCompatibility
[468] Fix | Delete
# Returns the next prime number and forwards internal pointer.
[469] Fix | Delete
def succ
[470] Fix | Delete
@generator.succ
[471] Fix | Delete
end
[472] Fix | Delete
alias next succ
[473] Fix | Delete
[474] Fix | Delete
# Overwrites Prime#each.
[475] Fix | Delete
#
[476] Fix | Delete
# Iterates the given block over all prime numbers. Note that enumeration
[477] Fix | Delete
# starts from the current position of internal pointer, not rewound.
[478] Fix | Delete
def each
[479] Fix | Delete
return @generator.dup unless block_given?
[480] Fix | Delete
loop do
[481] Fix | Delete
yield succ
[482] Fix | Delete
end
[483] Fix | Delete
end
[484] Fix | Delete
end
[485] Fix | Delete
end
[486] Fix | Delete
[487] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function