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

Function solution

project_euler/problem_122/sol1.py:62–85  ·  view source on GitHub ↗

Calculates sum of smallest number of multiplactions for each number up to and including n. >>> solution(1) 0 >>> solution(2) 1 >>> solution(14) 45 >>> solution(15) 50

(n: int = 200)

Source from the content-addressed store, hash-verified

60
61
62def solution(n: int = 200) -> int:
63 """
64 Calculates sum of smallest number of multiplactions for each number up to
65 and including n.
66
67 >>> solution(1)
68 0
69 >>> solution(2)
70 1
71 >>> solution(14)
72 45
73 >>> solution(15)
74 50
75 """
76 total = 0
77 for i in range(2, n + 1):
78 max_length = 0
79 while True:
80 nums = [1]
81 max_length += 1
82 if solve(nums=nums, goal=i, depth=max_length):
83 break
84 total += max_length
85 return total
86
87
88if __name__ == "__main__":

Callers 1

sol1.pyFile · 0.70

Calls 1

solveFunction · 0.70

Tested by

no test coverage detected