Skip to content

Instantly share code, notes, and snippets.

@metallurgix
Created July 7, 2014 18:24
Show Gist options
  • Save metallurgix/c255f1ff37ee5e6d7978 to your computer and use it in GitHub Desktop.
Save metallurgix/c255f1ff37ee5e6d7978 to your computer and use it in GitHub Desktop.
Checking for Prime Number
def prime? n
return true if n == 2
return false if n < 2 or n % 2 == 0
for d in (3..Math.sqrt(n).to_i).step(2) do
return false if n % d == 0
end
return true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment