Created
August 29, 2012 16:05
-
-
Save 0xeuclid/3514907 to your computer and use it in GitHub Desktop.
Find prime numbers
This file contains hidden or 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
=begin | |
If you want to find prime numbers less than N | |
then use each prime number form 2 to N**0.5 to test. | |
=end | |
print "2, 3, 5, 7, " | |
for i in (10..100) | |
if (i%2 != 0 and i%3 != 0 and i%5!=0 and i%7!=0) | |
print "#{i}, " | |
end | |
end | |
puts | |
# Output: | |
# 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment