<?xml version="1.0" encoding="windows-1252"?>
<node id="21580" title="RE: sieve of erothenes" created="2000-07-07 21:01:32" updated="2005-07-19 14:08:39">
<type id="11">
note</type>
<author id="20321">
ferrency</author>
<data>
<field name="doctext">
Here is a prime number verifier that Abigail presented at 
his talk entitled &lt;a href=http://www.foad.org/%7Eabigail/Perl/Talks/Japhs/&gt;
"JAPHs and Other Obscure Signatures"&lt;/a&gt; at YAPC 19100.
Very clever, very short, but I can't say much for the performance:

&lt;code&gt;
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
&lt;/code&gt;

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:&lt;p&gt;
&lt;code&gt;
for(1..100){push@_,$_ if (1 x $_) !~ /^1?$|^(11+?)\1+$/}
&lt;/code&gt;

I think that's shorter, no?&lt;br&gt;
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.
&lt;p&gt;
Alan

</field>
<field name="root_node">
20633</field>
<field name="parent_node">
20633</field>
</data>
</node>
