Created
April 18, 2012 13:30
-
-
Save shieldsd/2413565 to your computer and use it in GitHub Desktop.
Project Euler #41
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 chain | |
from math import sqrt | |
def comb(l): | |
if len(l) == 0: | |
yield [] | |
else: | |
for i in range(len(l)): | |
for cc in comb(l[:i] + l[i + 1:]): | |
yield [l[i]] + cc | |
def combn(n): | |
l = [c for c in str(n)] | |
return [int(''.join(x)) for x in comb(l)] | |
def isprime(n): | |
for x in range(2, int(sqrt(n)) + 1): | |
if n % x == 0: | |
return 0 | |
return 1 | |
print max(x for x in | |
(chain(*[combn(int('123456789'[:i])) | |
for i in range(1, 8)])) if isprime(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment