Skip to content

Commit 5e7b27e

Browse files
committed
Add solution for the euler project problem 137.
1 parent 0c8cf8e commit 5e7b27e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

project_euler/problem_137/__init__.py

Whitespace-only changes.

project_euler/problem_137/sol1.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Project Euler Problem 137: https://projecteuler.net/problem=137
3+
4+
Fibonacci Golden Nuggets
5+
6+
The polynomial sequence can be rewritten in the finite form:
7+
8+
A_F(x) = x / (1 - x - x^2)
9+
10+
And then the problem is to solve for it for rational x that give A_F(x) as positive
11+
integer. It turns out that the solution is for the n-th golden nugget is given by
12+
F(2n) * F(2n + 1), where F(k) is the k'th Fibonacci number.
13+
14+
Reference: https://oeis.org/A081018
15+
16+
"""
17+
18+
19+
def solution(n: int = 15) -> int:
20+
"""
21+
It calculates fibonachi numbers 2n and 2n+1, and returns their product.
22+
23+
>>> solution(3)
24+
104
25+
>>> solution(10)
26+
74049690
27+
"""
28+
29+
k = 2 * n
30+
31+
fib1 = fib2 = 1
32+
for _ in range(k - 1):
33+
fib1, fib2 = fib2, fib1 + fib2
34+
35+
return fib1 * fib2
36+
37+
38+
if __name__ == "__main__":
39+
print(f"{solution() = }")

0 commit comments

Comments
 (0)