Created
April 3, 2012 09:20
-
-
Save shieldsd/2290619 to your computer and use it in GitHub Desktop.
Project Euler #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import count | |
from itertools import islice | |
from math import sqrt | |
def truncated(n): | |
l, s = [], 10 | |
while n / s > 0: | |
l.extend([n / s, n % s]) | |
s *= 10 | |
return set(l) | |
def prime(): | |
primes = [] | |
for n in count(2): | |
composite = 0 | |
for p in primes: | |
if not n % p: | |
composite = 1 | |
break | |
elif p ** 2 > n: | |
break | |
if not composite: | |
primes.append(n) | |
yield n | |
def isprime(n): | |
if n < 2: | |
return 0 | |
for x in range(2, int(sqrt(n)) + 1): | |
if n % x == 0: | |
return 0 | |
return 1 | |
def isprimel(l): | |
for p in l: | |
if not isprime(p): | |
return 0 | |
return 1 | |
print sum(islice((p | |
for p in prime() | |
if isprimel(truncated(p)) | |
and p > 7), 11)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment