Skip to content

Instantly share code, notes, and snippets.

@sharnie
Created May 12, 2014 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharnie/ee84014375136694b8ba to your computer and use it in GitHub Desktop.
Save sharnie/ee84014375136694b8ba to your computer and use it in GitHub Desktop.
Finding a prime number in Ruby
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