Skip to content
Open
Changes from all 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
24 changes: 12 additions & 12 deletions maths/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ def fib_iterative(n: int) -> list[int]:
def fib_recursive(n: int) -> list[int]:
"""
Calculates the first n (0-indexed) Fibonacci numbers using recursion
>>> fib_iterative(0)
>>> fib_recursive(0)
[0]
>>> fib_iterative(1)
>>> fib_recursive(1)
[0, 1]
>>> fib_iterative(5)
>>> fib_recursive(5)
[0, 1, 1, 2, 3, 5]
>>> fib_iterative(10)
>>> fib_recursive(10)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib_iterative(-1)
>>> fib_recursive(-1)
Traceback (most recent call last):
...
ValueError: n is negative
Expand All @@ -119,7 +119,7 @@ def fib_recursive_term(i: int) -> int:
>>> fib_recursive_term(-1)
Traceback (most recent call last):
...
Exception: n is negative
ValueError: n is negative
"""
Comment on lines 119 to 123
Copy link

Copilot AI Jan 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doctest examples in this inner fib_recursive_term docstring won’t be collected by pytest’s --doctest-modules because fib_recursive_term is defined inside fib_recursive and is not a module-level object. If you want these examples to run in CI, move them into fib_recursive’s docstring or promote fib_recursive_term to a module-level helper.

Copilot uses AI. Check for mistakes.
if i < 0:
raise ValueError("n is negative")
Expand All @@ -135,15 +135,15 @@ def fib_recursive_term(i: int) -> int:
def fib_recursive_cached(n: int) -> list[int]:
"""
Calculates the first n (0-indexed) Fibonacci numbers using recursion
>>> fib_iterative(0)
>>> fib_recursive_cached(0)
[0]
>>> fib_iterative(1)
>>> fib_recursive_cached(1)
[0, 1]
>>> fib_iterative(5)
>>> fib_recursive_cached(5)
[0, 1, 1, 2, 3, 5]
>>> fib_iterative(10)
>>> fib_recursive_cached(10)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib_iterative(-1)
>>> fib_recursive_cached(-1)
Traceback (most recent call last):
...
ValueError: n is negative
Expand Down Expand Up @@ -176,7 +176,7 @@ def fib_memoization(n: int) -> list[int]:
[0, 1, 1, 2, 3, 5]
>>> fib_memoization(10)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> fib_iterative(-1)
>>> fib_memoization(-1)
Traceback (most recent call last):
...
ValueError: n is negative
Expand Down