Skip to content

Instantly share code, notes, and snippets.

@seanhandley

seanhandley/prime_re.rb

Last active Sep 9, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.