from lib_misc import permutations


def is_sub_string_divisible(s):
    s = "".join(s)
    if int(s[1:4]) % 2 != 0:
        return False
    if int(s[2:5]) % 3 != 0:
        return False
    if int(s[3:6]) % 5 != 0:
        return False
    if int(s[4:7]) % 7 != 0:
        return False
    if int(s[5:8]) % 11 != 0:
        return False
    if int(s[6:9]) % 13 != 0:
        return False
    if int(s[7:10]) % 17 != 0:
        return False
    return True


def euler_043():
    return sum([int("".join(p))
                for p in permutations("0123456789")
                if is_sub_string_divisible(p)])


if __name__ == "__main__":
    print("e043.py: " + str(euler_043()))
    assert(euler_043() == 16695334890)
