Skip to content

Instantly share code, notes, and snippets.

@shieldsd
Created April 18, 2012 13:55
Show Gist options
  • Save shieldsd/2413735 to your computer and use it in GitHub Desktop.
Save shieldsd/2413735 to your computer and use it in GitHub Desktop.
Project Euler #43
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