-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob0025.py
More file actions
34 lines (23 loc) · 842 Bytes
/
prob0025.py
File metadata and controls
34 lines (23 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
Project Euler Problem 25. https://projecteuler.net/problem=25
"""
import math
def fibonacci_gen():
"""Fibonacci generator"""
previous = 0
current = 1
while True:
yield current
following = previous + current
previous = current
current = following
# Using the limit ratio of Fibonacci numbers to figure out when we get over 1000 digits
fibonacci = fibonacci_gen()
# The Golden ratio
base = (1 + 5**.5)/2
for i in range(1, 30):
print(f"{i}: {next(fibonacci)} -- {round(base**(i-2)*1.17082, 0)}")
# The ith Fibonacci is the golden ratio raised to the (i-2) power, times a number slightly over 1.
adjustment = 1.17082**(1/999)
# This solves for i-2 when the fibonacci number is 10^999 (i.e., 1000 digits)
print(999*math.log(10/adjustment, base))