MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / is_substring_divisible

Function is_substring_divisible

project_euler/problem_043/sol1.py:24–48  ·  view source on GitHub ↗

Returns True if the pandigital number passes all the divisibility tests. >>> is_substring_divisible((0, 1, 2, 4, 6, 5, 7, 3, 8, 9)) False >>> is_substring_divisible((5, 1, 2, 4, 6, 0, 7, 8, 3, 9)) False >>> is_substring_divisible((1, 4, 0, 6, 3, 5, 7, 2, 8, 9))

(num: tuple)

Source from the content-addressed store, hash-verified

22
23
24def is_substring_divisible(num: tuple) -> bool:
25 """
26 Returns True if the pandigital number passes
27 all the divisibility tests.
28 >>> is_substring_divisible((0, 1, 2, 4, 6, 5, 7, 3, 8, 9))
29 False
30 >>> is_substring_divisible((5, 1, 2, 4, 6, 0, 7, 8, 3, 9))
31 False
32 >>> is_substring_divisible((1, 4, 0, 6, 3, 5, 7, 2, 8, 9))
33 True
34 """
35 if num[3] % 2 != 0:
36 return False
37
38 if (num[2] + num[3] + num[4]) % 3 != 0:
39 return False
40
41 if num[5] % 5 != 0:
42 return False
43
44 tests = [7, 11, 13, 17]
45 for i, test in enumerate(tests):
46 if (num[i + 4] * 100 + num[i + 5] * 10 + num[i + 6]) % test != 0:
47 return False
48 return True
49
50
51def solution(n: int = 10) -> int:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected