[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [MacPerl] Prime Numbers



This is not the most efficient way to determine prime numbers.

It's also not the most readable.

But so far, it's been the most fun. :)

#(c) Creede Lambard -- licensed just like Perl!
$l=10000;$f = "%5d\n";$b="B*";$s=pack($b,1x$l);
for(2..($l**.5))    {$s&=pack($b,substr((1x$_).
(((1x($_-1)).0)x($l/$_)),0,$l))}     for(2..$l)
{printf($f,$_)if(substr(unpack($b,$s),$_-1,1))}

Looks like I was right, using a set of bits to simulate Eratosthenes' sieve
was pretty silly.

I really worked hard at getting this to be one solid brick of code with no
spaces, but it didn't quite turn out that way. Unfortunately it's also
probably a little too straightforward to stand a chance in the Obfuscated
Perl Contest. Also, unfortunately, my lunch break was over before this could
become any sillier, more obfuscated, or more compact. C'est la vie.

-- Creede


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org