note
ferrency
Here is a prime number verifier that Abigail presented at
his talk entitled <a href=http://www.foad.org/%7Eabigail/Perl/Talks/Japhs/>
"JAPHs and Other Obscure Signatures"</a> at YAPC 19100.
Very clever, very short, but I can't say much for the performance:
<code>
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
</code>
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:<p>
<code>
for(1..100){push@_,$_ if (1 x $_) !~ /^1?$|^(11+?)\1+$/}
</code>
I think that's shorter, no?<br>
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.
<p>
Alan
20633
20633