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

Function solution

project_euler/problem_078/sol1.py:22–54  ·  view source on GitHub ↗

>>> solution(1) 1 >>> solution(9) 14 >>> solution() 55374

(number: int = 1000000)

Source from the content-addressed store, hash-verified

20
21
22def solution(number: int = 1000000) -> int:
23 """
24 >>> solution(1)
25 1
26
27 >>> solution(9)
28 14
29
30 >>> solution()
31 55374
32 """
33 partitions = [1]
34
35 for i in itertools.count(len(partitions)):
36 item = 0
37 for j in itertools.count(1):
38 sign = -1 if j % 2 == 0 else +1
39 index = (j * j * 3 - j) // 2
40 if index > i:
41 break
42 item += partitions[i - index] * sign
43 item %= number
44 index += j
45 if index > i:
46 break
47 item += partitions[i - index] * sign
48 item %= number
49
50 if item == 0:
51 return i
52 partitions.append(item)
53
54 return 0
55
56
57if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 2

countMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected