43.py 641 B

123456789101112131415161718
  1. from string import digits
  2. from itertools import permutations
  3. substringDivisibility = 0
  4. for i in permutations(digits, 10):
  5. # Reduce tuples into a string
  6. i = ''.join(i)
  7. # Create list of all list triplets
  8. divisibilityList = map(int, [i[1:4], i[2:5], i[3:6], i[4:7], i[5:8], i[6:9], i[7:10]])
  9. # Check for all divisibility rules
  10. if divisibilityList[0] % 2 == 0 and divisibilityList[1] % 3 == 0 and divisibilityList[2] % 5 == 0 and divisibilityList[3] % 7 == 0 and divisibilityList[4] % 11 == 0 and divisibilityList[5] % 13 == 0 and divisibilityList[6] % 17 == 0:
  11. substringDivisibility += int(i)
  12. print i
  13. print substringDivisibility