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

Function fibonacci_digits_index

project_euler/problem_025/sol1.py:58–80  ·  view source on GitHub ↗

Computes incrementing Fibonacci numbers starting from 3 until the length of the resulting Fibonacci result is the input value n. Returns the term of the Fibonacci sequence where this occurs. >>> fibonacci_digits_index(1000) 4782 >>> fibonacci_digits_index(100) 476 >

(n: int)

Source from the content-addressed store, hash-verified

56
57
58def fibonacci_digits_index(n: int) -> int:
59 """
60 Computes incrementing Fibonacci numbers starting from 3 until the length
61 of the resulting Fibonacci result is the input value n. Returns the term
62 of the Fibonacci sequence where this occurs.
63
64 >>> fibonacci_digits_index(1000)
65 4782
66 >>> fibonacci_digits_index(100)
67 476
68 >>> fibonacci_digits_index(50)
69 237
70 >>> fibonacci_digits_index(3)
71 12
72 """
73 digits = 0
74 index = 2
75
76 while digits < n:
77 index += 1
78 digits = len(str(fibonacci(index)))
79
80 return index
81
82
83def solution(n: int = 1000) -> int:

Callers 1

solutionFunction · 0.85

Calls 1

fibonacciFunction · 0.70

Tested by

no test coverage detected