Skip to content

Instantly share code, notes, and snippets.

@jakedobkin
Created December 8, 2011 20:50
Show Gist options
  • Select an option

  • Save jakedobkin/1448512 to your computer and use it in GitHub Desktop.

Select an option

Save jakedobkin/1448512 to your computer and use it in GitHub Desktop.
euler 43 python
# let's try using the built in permutation function!
import itertools
x = itertools.permutations('0123456789', 10)
sum = 0
for i in x:
string= "".join(list(i))
number = int(string)
# you can add a number of these if requirements using divisibility rules- i picked the obvious three
if (number > 1000000000 and int(i[3])%2==0 and int(i[5])%5==0):
if (int(i[1]+i[2]+i[3])%2==0 and int(i[2]+i[3]+i[4])%3==0 and int(i[3]+i[4]+i[5])%5==0 and int(i[4]+i[5]+i[6])%7==0 and int(i[5]+i[6]+i[7])%11==0 and int(i[6]+i[7]+i[8])%13==0 and int(i[7]+i[8]+i[9])%17==0):
sum = sum + number
print "sum is",sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment