Skip to content

Instantly share code, notes, and snippets.

View tcdowney's full-sized avatar

Tim Downey tcdowney

View GitHub Profile
@tcdowney
tcdowney / primeperms.rb
Last active August 29, 2015 14:00 — forked from baweaver/primeperms.rb
Use the sieve :)
def eratosthenes(n)
nums = [nil, 1, *2..n]
(2..Math.sqrt(n)).each do |i|
(i**2..n).step(i){|m| nums[m] = nil} if nums[i]
end
nums
end
primes_to_million = eratosthenes(1_000_000)