Skip to content

Instantly share code, notes, and snippets.

@jtallant
Created July 2, 2012 03:21
Show Gist options
  • Save jtallant/3030806 to your computer and use it in GitHub Desktop.
Save jtallant/3030806 to your computer and use it in GitHub Desktop.
is_prime? ruby method
def is_prime?(n)
((2..(Math.sqrt(n)))).each do |i|
return false if n % i == 0
end
return true
end
@Karpot
Copy link

Karpot commented Jul 3, 2015

a check is needed that 0 and 1 are not prime numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment