WhatfettlePrimes by Regex

Via Otu Ekanem, a regex to discover prime numbers. Wow!

import re
p = re.compile(r'@^1?$|^(11+?)\1+$')
for i in xrange(20000):
    if p.match('1'*i) is None:
        print i

Cool, but on my slowbook the Sieve of Eratosthenes is some 2000 times quicker:

primes = []
for i in xrange(2, 20000):
    isprime = 1
    for prime in primes:
        if (i % prime) == 0:
            isprime = 0
        if i < prime*prime:

    if isprime:
        print i

Either way I don’t think we’re going to win The COOP Prize, unless we find a cheat.