I've searched every site I can imagine and am unable to determine the base algorithm that ruby 1.8 uses to create a list of primes in the Prime class under mathn. The following is a runnable version of the succ method, called 100 times (in order to find the 100th prime). Does anyone know how this works?
number_of_primes = 100
seed = 1
primes = Array.new
counts = Array.new
while primes.size < number_of_primes
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)
end
puts seed
The actual code is of course: http://ruby-doc.org/stdlib-1.8.7/libdoc/mathn/rdoc/Prime.html
It doesn't look like a sieve algorithm as there is no predefined list to sift through, it's not a trial division algorithm as there are no division or modulus operations. I'm totally stumped.