interplane.Get Omega
Read in your language

MojoLlama

Archived Mojo/MAX quantizer and serving research repository (read-only history)

Brought by drakestapleton

branch main Branches Tags History

MojoLlama / fibonacci.py

18 lines · 458 bytes Raw Blame History
1def fibonacci(n: int) -> int:
2 """Return the nth Fibonacci number using iterative approach.
3
4 Args:
5 n: The position in the Fibonacci sequence (0-indexed).
6
7 Returns:
8 The nth Fibonacci number where fibonacci(0) = 0, fibonacci(1) = 1.
9
10 Raises:
11 ValueError: If n is negative.
12 """
13 if n < 0:
14 raise ValueError("n must be non-negative")
15 a, b = 0, 1
16 for _ in range(n):
17 a, b = b, a + b
18 return a