APM: Perl Challenge

Wayne Walker wwalker at broadq.com
Sun Mar 23 09:05:57 CST 2003


Please don't reply to the list!

Below is a program with a regex that tests for prime numbers.  I'll buy
dinner at PokeJo's before the next meeting for the first person to send
me a description of how it works.  I'm assuming anyone who has seen this
before won't try to get the prize.  Next Monday I'll post the correct
answers I got and who sent them.  That email will have appropriate
subject to allow those still working on the problem to not accidentally
see the answer.

No, I did not come up with the regex.  It's attributed to an Abigail
(aparently of the Athens Perl Mongers, but not certain).

The coupe de graz will be to also describe the function of time versus
the change in $i's max value (e.g. "if we search 1-200 instead of 1-100,
it takes 1024 times as long to run, meaning that the ratio function is
k * (i2/i1)^10).

#!/usr/bin/perl

foreach $i (1..100)
{
	if ((1 x $i) !~ /^1?$|^(11+?)\1+$/)
	{
		print "$i is prime\n";
		$j = $i; 
	}
}

-- 

Wayne Walker

www.broadq.com :)  Bringing digital video and audio to the living room



More information about the Austin mailing list