Skip to content

Commit 9a38038

Browse files
committed
Add doctests and documentation for the project euler problem 122.
1 parent f86430b commit 9a38038

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Diff for: project_euler/problem_122/sol1.py

+30
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,29 @@
22
Project Euler Problem 122: https://projecteuler.net/problem=122
33
44
Efficient Exponentiation
5+
6+
It uses the fact that for rather small n, applicable for this problem, the solution
7+
for each number
8+
can be formed by increasing the largest element.
9+
10+
References:
11+
- https://en.wikipedia.org/wiki/Addition_chain
12+
13+
>>> solution(14)
14+
45
515
"""
616

717

818
def solve(nums: list[int], goal: int, depth: int) -> bool:
19+
"""
20+
Checks if nums can can have a sum equal to goal, given that length of nums does
21+
not exceed depth.
22+
23+
>>> solve([1], 2, 2)
24+
True
25+
>>> solve([1], 2, 0)
26+
False
27+
"""
928
if len(nums) > depth:
1029
return False
1130
for el in nums:
@@ -19,6 +38,17 @@ def solve(nums: list[int], goal: int, depth: int) -> bool:
1938

2039

2140
def solution(n: int = 200) -> int:
41+
"""
42+
Calculates sum of smallest number of multiplactions for each number up to
43+
and including n.
44+
45+
>>> solution(1)
46+
0
47+
>>> solution(2)
48+
1
49+
>>> solution(15)
50+
50
51+
"""
2252
m = [0]
2353
for i in range(2, n + 1):
2454
max_length = 0

0 commit comments

Comments
 (0)