The problem here is to find the sum of all of the 0-9 pandigital numbers that meet certain conditions. 

Let d1 be the 1st digit, d2 be the 2nd digit, and so on. We are looking for numbers where:

  • d2d3d4 is divisible by 2
  • d3d4d5 is divisible by 3
  • d4d5d6 is divisible by 5
  • d5d6d7 is divisible by 7
  • d6d7d8 is divisible by 11
  • d7d8d9 is divisible by 13
  • d8d9d10 is divisible by 17

I solved this problem by first generating all of the 0-9 pandigital numbers with Python's permutations function. Then I removed all of the permutations that had zero as their first digit (since leading zeros aren't significant). Next, I removed all the numbers where d4 isn't even or here d6 is anything other than a 5 or 0.

After that I just worked through the remaining pandigitals and checked the divisibility of the remaining three digit strings. In my final script I end up checking all of the sub-strings. Clearly this is not necessary since once we find that one test is failed there is no need to check the others. However, since we only end up with a few pandigitals to check it doesn't make any difference.

Once I got the answer, I read the forum and discovered that this is not the most efficient method. Imagine my surprise!

def makeNumbers():
    initial =list(permutations([0,1,2,3,4,5,6,7,8,9]))
    pans = []
    
    for item in initial:
        if item[0] != 0 and item[3]%2 == 0 \
        and (item[5] == 5 or item[5] == 0): pans.append(item)
        
    return pans

print('Generating candidate 0-9 pandigitals')
candidates = makeNumbers()

qualified = []
print('Checking...')
for item in candidates:
    digits, success = [], True
    
    for d in item: digits.append(d)
    
    d345 = digits[2]*100 + digits[3]*10 + digits[4]
    d567 = digits[4]*100 + digits[5]*10 + digits[6]
    d678 = digits[5]*100 + digits[6]*10 + digits[7]
    d789 = digits[6]*100 + digits[7]*10 + digits[8]
    d890 = digits[7]*100 + digits[8]*10 + digits[9]
    
    if d345 % 3 != 0: success = False
    if d567 % 7 != 0: success = False
    if d678 % 11 != 0: success = False
    if d789 % 13 != 0: success = False
    if d890 % 17 != 0: success = False
    
    if success:
        result = ''
        for d in digits:
            result = result + str(d)
        qualified.append(int(result))

answer = 0
for x in qualified:
    answer += x

print (answer)