Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions project_euler/problem_25/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
"""


def fibonacci(n):
if n == 1 or type(n) is not int:
def fibonacci(n: int) -> int:
"""
Computes the Fibonacci number for input n by iterating through n numbers
and creating an array of ints using the Fibonacci formula.
Returns the nth element of the array.
"""
if n == 1:
return 0
elif n == 2:
return 1
Expand All @@ -38,7 +43,11 @@ def fibonacci(n):
return sequence[n]


def fibonacci_digits_index(n):
def fibonacci_digits_index(n: int) -> int:
"""
Computes incrementing Fibonacci numbers starting from 3 until the length
of the resulting Fibonacci result is the input value n.
"""
digits = 0
index = 2

Expand All @@ -49,8 +58,9 @@ def fibonacci_digits_index(n):
return index


def solution(n):
"""Returns the index of the first term in the Fibonacci sequence to contain
def solution(n: int = 1000) -> int:
"""
Returns the index of the first term in the Fibonacci sequence to contain
n digits.

>>> solution(1000)
Expand Down
2 changes: 1 addition & 1 deletion project_euler/problem_25/sol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def fibonacci_generator():
yield b


def solution(n):
def solution(n: int = 1000) -> int:
"""Returns the index of the first term in the Fibonacci sequence to contain
n digits.

Expand Down
4 changes: 2 additions & 2 deletions project_euler/problem_25/sol3.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"""


def solution(n):
def solution(n: int = 1000) -> int:
"""Returns the index of the first term in the Fibonacci sequence to contain
n digits.

Expand All @@ -45,7 +45,7 @@ def solution(n):
f = f1 + f2
f1, f2 = f2, f
index += 1
for j in str(f):
for _ in str(f):
i += 1
if i == n:
break
Expand Down