Baseline: tree as shared

This commit is contained in:
alexm committed 2026-10-05 03:03:38 +00:00
commit 31f2fb8a5a
1679 files changed
+1024562

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
# 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))