forked from Tecmax/JavaAndroidPractise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp043.py
More file actions
27 lines (19 loc) · 631 Bytes
/
Copy pathp043.py
File metadata and controls
27 lines (19 loc) · 631 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#
# 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())