Fun with primality testing

François Pinard pinard at iro.umontreal.ca
Fri May 12 19:16:51 EDT 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