Created
October 31, 2012 20:45
-
-
Save colllin/3989752 to your computer and use it in GitHub Desktop.
ruby prime number generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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