http://qs321.pair.com?node_id=21580


in reply to sieve of erothenes

Here is a prime number verifier that Abigail presented at his talk entitled "JAPHs and Other Obscure Signatures" at YAPC 19100. Very clever, very short, but I can't say much for the performance:
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
This takes a number as a parameter, and checks to see whether it's prime or not. I modified it a bit to stuff @_ with primes, and got this:

for(1..100){push@_,$_ if (1 x $_) !~ /^1?$|^(11+?)\1+$/}
I think that's shorter, no?
As I said, I can't claim credit for this! But it's definitely worth noting. There's an explanation of how it works on his talk web site.

Alan