Fun with primality testing

François Pinard pinard at iro.umontreal.ca
Sat May 13 01:16:51 CEST 2000


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

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






More information about the Python-list mailing list