Created
December 25, 2011 05:43
-
-
Save dekokun/1518774 to your computer and use it in GitHub Desktop.
愚直なエラトステネスのふるい(動きがわかるよ)
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
ns = Array.new(99){|i| i+2} | |
result = Array.new | |
while ns.length != 0 | |
prime = ns.shift | |
ns.delete_if{|x| x % prime == 0} | |
result.push prime | |
p ns | |
p result | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
本当は、すべての数について走査する必要はない。高々100の平方根までで問題ない