Files
pplus-library/mojo/stress/fibonacci-memo.mojo
T
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

26 lines
728 B
Mojo

# probe: recursion with a Dict memo passed as mut
# status: the expected output is Programming+'s interpreter's prediction; corpus.py verify confirms or refutes it on godbolt
# expect-stdout: 0 0
# expect-stdout: 5 5
# expect-stdout: 10 55
# expect-stdout: 15 610
# expect-stdout: 20 6765
# expect-stdout: 25 75025
# expect-stdout: 30 832040
# expect-stdout: memo size: 29
def fib(n: Int, mut memo: Dict[Int, Int]) raises -> Int:
if n < 2:
return n
if n in memo:
return memo[n]
var v = fib(n - 1, memo) + fib(n - 2, memo)
memo[n] = v
return v
def main() raises:
var memo = Dict[Int, Int]()
for n in range(0, 31, 5):
print(n, fib(n, memo))
print("memo size:", len(memo))