10 lines
229 B
Text
10 lines
229 B
Text
|
|
function fib(x: int): int = (
|
||
|
|
let cache = {} in
|
||
|
|
let fibc x = if x<=1 then x else (
|
||
|
|
if x not in cache then
|
||
|
|
cache[x] = fibc(x-1) + fibc(x-2);
|
||
|
|
cache[x]
|
||
|
|
) in fibc(x)
|
||
|
|
);;
|
||
|
|
for x in range(10) do print(fib(x))
|