Created
May 26, 2011 08:28
-
-
Save andruby/992773 to your computer and use it in GitHub Desktop.
Find the first 1000 primes quickly in Ruby
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
getal = 2 | |
primes = [2] | |
begin | |
getal += 1 | |
primes << getal unless primes.any? { |deler| getal % deler == 0 } | |
end until primes.size >= 1000 | |
p primes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment