Created
April 18, 2012 13:55
-
-
Save shieldsd/2413735 to your computer and use it in GitHub Desktop.
Project Euler #43
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
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 divisible(n): | |
primes = (2, 3, 5, 7, 11, 13, 17) | |
s = str(n) | |
for i in range(1, 8): | |
if int(s[i:i+3]) % primes[i - 1] != 0: | |
return 0 | |
return 1 | |
print sum(x for x in combn(1234567890) if divisible(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment