vendredi 15 octobre 2010

Euler #43

#!/usr/bin/env python
from libeuler import str_permutations
if __name__ == '__main__':
nums = str_permutations('0123456789')
r = []
for n in nums:
n1 = int(n[1:4])
n2 = int(n[2:5])
n3 = int(n[3:6])
n4 = int(n[4:7])
n5 = int(n[5:8])
n6 = int(n[6:9])
n7 = int(n[7:10])
if n1 % 2 == 0 and \
n2 % 3 == 0 and \
n3 % 5 == 0 and \
n4 % 7 == 0 and \
n5 % 11 == 0 and \
n6 % 13 == 0 and \
n7 % 17 == 0:
print n
r += [int(n)]
print sum(r)
view raw 43.py hosted with ❤ by GitHub

Aucun commentaire:

Enregistrer un commentaire