Skip to content

Instantly share code, notes, and snippets.

@bguzryanto
Last active December 17, 2015 16:29
Show Gist options
  • Save bguzryanto/5639004 to your computer and use it in GitHub Desktop.
Save bguzryanto/5639004 to your computer and use it in GitHub Desktop.
Sieve
def sieve(to)
n = Array.new(to, true)
for i in 2..Math.sqrt(to) do
if n.at(i) == true
j = i;
while j*i < to do
n[i*j] = false
j += 1
end
end
end
for i in 2..to do
if n.at(i) == true
puts i
end
end
end
sieve(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment