Mercurial > hg > euler
view problem37.py @ 14:49c96972949d default tip
#50 rewrite of solution
author | Dominic Cleal <dominic@computerkb.co.uk> |
---|---|
date | Mon, 01 Dec 2008 19:11:55 +0000 |
parents | 449e1d2e103c |
children |
line wrap: on
line source
import math import primes def matches(i, s, fn): si = str(i) while len(si) > 0: if not s.isprime(int(si)): return False si = fn(si) return True tr = [] s = primes.testsieve() for i in s.sieve(): if i > 9 and matches(i, s, lambda s: s[1:]) and matches(i, s, lambda s: s[:-1]): print "Truncatable: %d" % (i) tr.append(i) if len(tr) == 11: print "Eleven found, sum = %d" % (sum(tr)) break