Skip to content

Instantly share code, notes, and snippets.

@colllin
Created October 31, 2012 20:45
Show Gist options
  • Save colllin/3989752 to your computer and use it in GitHub Desktop.
Save colllin/3989752 to your computer and use it in GitHub Desktop.
ruby prime number generator
#!/bin/ruby
def calculatePrime
list = (2..7050000).to_a
print "2 "
list = list.select(&:odd?)
list.each_with_index.each do |n, i|
next if n == nil
print "#{n} "
while i < list.count do
list[i] = nil
i+=n
end
end
end
calculatePrime()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment