Created
July 2, 2012 03:21
-
-
Save jtallant/3030806 to your computer and use it in GitHub Desktop.
is_prime? ruby method
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
def is_prime?(n) | |
((2..(Math.sqrt(n)))).each do |i| | |
return false if n % i == 0 | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
a check is needed that 0 and 1 are not prime numbers.