Return to Snippet

Revision: 6788
at June 14, 2008 11:08 by banzaiman


Updated Code
^1?$|^(11+?)\1+$

Revision: 6787
at June 14, 2008 11:07 by banzaiman


Updated Code
/^1?$|^(11+?)\1+$/

Revision: 6786
at June 14, 2008 11:02 by banzaiman


Initial Code
print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/

Initial URL


Initial Description
By the legendary abigail.  Fails to match if and only if it is matched against a prime number of 1's.  That is, '11' fails, but '1111' does not.

I once heard him talk why this works, but I forgot most of it.

Initial Title
Prime number tester

Initial Tags
regex

Initial Language
Regular Expression