Skip to content

Instantly share code, notes, and snippets.

@JakeAustwick
Created February 12, 2012 17:11
Show Gist options
  • Save JakeAustwick/1809678 to your computer and use it in GitHub Desktop.
Save JakeAustwick/1809678 to your computer and use it in GitHub Desktop.
# This works
def sieve_upto(top)
sieve = []
for i in 2 .. top
sieve[i] = i
end
for i in 2 .. Math.sqrt(top)
next unless sieve[i]
(i*i).step(top, i) do |j|
sieve[j] = nil
end
end
sieve.compact
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment