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

Function solution

project_euler/problem_025/sol2.py:52–69  ·  view source on GitHub ↗

Returns the index of the first term in the Fibonacci sequence to contain n digits. >>> solution(1000) 4782 >>> solution(100) 476 >>> solution(50) 237 >>> solution(3) 12

(n: int = 1000)

Source from the content-addressed store, hash-verified

50
51
52def solution(n: int = 1000) -> int:
53 """Returns the index of the first term in the Fibonacci sequence to contain
54 n digits.
55
56 >>> solution(1000)
57 4782
58 >>> solution(100)
59 476
60 >>> solution(50)
61 237
62 >>> solution(3)
63 12
64 """
65 answer = 1
66 gen = fibonacci_generator()
67 while len(str(next(gen))) < n:
68 answer += 1
69 return answer + 1
70
71
72if __name__ == "__main__":

Callers 1

sol2.pyFile · 0.70

Calls 1

fibonacci_generatorFunction · 0.85

Tested by

no test coverage detected