Fun with primality testing

Neel Krishnaswami neelk at brick.cswv.com
Fri May 12 19:54:52 EDT 2000


François Pinard <pinard at iro.umontreal.ca> wrote:
> Hi, people.
>
> For your mere enjoyment!  Here is Python code which prints primes
> below 1000.  At the local Perl mongers meeting, someone showed this
> nicety to me.
>
> 
> import re
> for n in range(2, 1000):
>     if not re.match('(11+)\\1+$', '1'*n):
>         print n

That's EVIL!

Regexps are clearly evolving towards becoming the mutant offspring of
Prolog and TECO -- obviously we will know the apocalypse is at hand
when Perl adds a cut operator to its pattern language.


Neel



More information about the Python-list mailing list