Skip to content

Instantly share code, notes, and snippets.

@seanhandley
Last active September 9, 2016 11:15
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 seanhandley/9af6a6c9f42b7a0e322b818977bc97fd to your computer and use it in GitHub Desktop.
Save seanhandley/9af6a6c9f42b7a0e322b818977bc97fd to your computer and use it in GitHub Desktop.
class Fixnum
def prime?
/^.?$|^(..+?)\1+$/ !~ '1'*self
end
end
0.prime? #=> false
1.prime? #=> false
2.prime? #=> true
3.prime? #=> true
4.prime? #=> false
5.prime? #=> true
6.prime? #=> false
7.prime? #=> true
8.prime? #=> false
9.prime? #=> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment