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 break if i < prime*prime: break if isprime: primes.append(i) print i
Either way I don't think we're going to win The COOP Prize, unless we find a cheat.