Skip to content

Instantly share code, notes, and snippets.

@IvanTorresEdge
Created February 2, 2012 06:45
Show Gist options
  • Save IvanTorresEdge/1722053 to your computer and use it in GitHub Desktop.
Save IvanTorresEdge/1722053 to your computer and use it in GitHub Desktop.
Find prime numbers using Sieve of Eratosthenes algorithm (Ruby)
#!/usr/bin/env ruby
n = 2..1000
o = []
p = []
for i in n
next if o.include? i
ii = i * 2
while ii <= n.last do
o << ii
ii = ii + i
end
p << i unless o.include?(i)
end
puts p.inspect
@IvanTorresEdge
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment