Created
May 12, 2014 17:38
-
-
Save sharnie/ee84014375136694b8ba to your computer and use it in GitHub Desktop.
Finding a prime number 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
def prime? num | |
return false if num <= 1 | |
i = 2 # starting point | |
while i < num | |
return false if num % i == 0 # num is not prime | |
i += 1 # increment i | |
end | |
return true # if the number is prime | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment