euler/euler007.rb

34 lines
598 B
Ruby

require 'progressbar'
def increasingSieve(size)
startingSize = 10
eSieve = []
while eSieve.length < size
eSieve = sieve(startingSize)
startingSize *= 2
end
eSieve
end
def sieve(n)
eSieve = (2..n).to_a
i = 0
pbar = ProgressBar.new("sieving", n)
while i < Math.sqrt(n)
j = i + 1
while (j < eSieve.length)
if (eSieve[j] > (i ** 2)) and ((eSieve[j] % eSieve[i]) == 0)
eSieve.delete_at j
pbar.inc
end
j += 1
end
i += 1
pbar.set(i + (n-eSieve.length))
end
pbar.finish
eSieve
end
puts increasingSieve(10001)[10000]