Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
28 lines (19 sloc) 631 Bytes
#
# Solution to Project Euler problem 43
# Copyright (c) Project Nayuki. All rights reserved.
#
# https://www.nayuki.io/page/project-euler-solutions
# https://github.com/nayuki/Project-Euler-solutions
#
import itertools
def compute():
ans = sum(int("".join(map(str, num)))
for num in itertools.permutations(list(range(10)))
if is_substring_divisible(num))
return str(ans)
DIVISIBILITY_TESTS = [2, 3, 5, 7, 11, 13, 17]
def is_substring_divisible(num):
return all((num[i + 1] * 100 + num[i + 2] * 10 + num[i + 3]) % p == 0
for (i, p) in enumerate(DIVISIBILITY_TESTS))
if __name__ == "__main__":
print(compute())