Problem 42

Sub-string divisibility

Problem 44

Sub-string divisibility

Problem 43

The number, 1406357289, is a 0 to 9 pandigital number because it is made up of each of the digits 0 to 9 in some order, but it also has a rather interesting sub-string divisibility property.
Let d1 be the 1st digit, d2 be the 2nd digit, and so on. In this way, we note the following:
Find the sum of all 0 to 9 pandigital numbers with this property.
from itertools import permutations


def run():
    total = 0

    # First 7 primes
    primes = [2, 3, 5, 7, 11, 13, 17]
    for item in permutations('1234567890'):
        if item[0] == '0':
            continue

        candidate = ''.join(item)
        is_divisible = True
        for idx, p in enumerate(primes):
            if int(candidate[idx + 1:idx + 4]) % p != 0:
                is_divisible = False
                break

        if is_divisible:
            total += int(candidate)

    return total