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)
| 50 | |
| 51 | |
| 52 | def 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 | |
| 72 | if __name__ == "__main__": |
no test coverage detected