We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0c8cf8e commit f86430bCopy full SHA for f86430b
project_euler/problem_122/__init__.py
project_euler/problem_122/sol1.py
@@ -0,0 +1,35 @@
1
+"""
2
+Project Euler Problem 122: https://projecteuler.net/problem=122
3
+
4
+Efficient Exponentiation
5
6
7
8
+def solve(nums: list[int], goal: int, depth: int) -> bool:
9
+ if len(nums) > depth:
10
+ return False
11
+ for el in nums:
12
+ if el + nums[-1] == goal:
13
+ return True
14
+ nums.append(el + nums[-1])
15
+ if solve(nums, goal, depth):
16
17
+ del nums[-1]
18
19
20
21
+def solution(n: int = 200) -> int:
22
+ m = [0]
23
+ for i in range(2, n + 1):
24
+ max_length = 0
25
+ while True:
26
+ nums = [1]
27
+ max_length += 1
28
+ if solve(nums, i, max_length):
29
+ break
30
+ m.append(len(nums))
31
+ return sum(m)
32
33
34
+if __name__ == "__main__":
35
+ print(f"{solution() = }")
0 commit comments