Fun with primality testing

ullrich at math.okstate.edu ullrich at math.okstate.edu
Sat May 13 15:27:37 EDT 2000


In article <oqzopv8il8.fsf at titan.progiciels-bpi.ca>,
  =?ISO-8859-1?Q?Fran=E7ois_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


     Tee-hee. [Insert what Emile said, except surely he figured
it out a lot quicker than I did...]

     It's like how Peano used to do primality testing. (It's well
known that using regular expressions is the efficient way to
do things, so this must be an efficient primality test. Keen.)

DU

> --
> François Pinard   http://www.iro.umontreal.ca/~pinard
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list