Last active
August 29, 2015 14:19
-
-
Save mindaslab/d6c8fe7e020f081b61a6 to your computer and use it in GitHub Desktop.
Primes in Ruby
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
class Fixnum | |
def prime? | |
return true if self == 1 | |
2.upto(self) do |num| | |
if self % num == 0 | |
return self == num | |
end | |
end | |
end | |
end | |
1.upto(100) do |num| | |
puts num if num.prime? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment