Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,24 @@
procedure main(A)
every write("fib(",a := numeric(!A),")=",fib(a))
end
procedure fib(n)
local source, i
static cache
initial {
cache := table()
cache[0] := 0
cache[1] := 1
}
if type(n) == "integer" & n >= 0 then
return n @ makeProc {{
i := @(source := &source) # 1
/cache[i] := ((i-1)@makeProc(^&current)+(i-2)@makeProc(^&current)) # 2
cache[i] @ source # 3
}}
end
procedure makeProc(A)
A := if type(A) == "list" then A[1]
return (@A, A) # prime and return
end

View file

@ -0,0 +1,9 @@
procedure fib(n)
local source, i
if type(n) == "integer" & n >= 0 then
return n @ makeProc {{
i := @(source := &source)
if i = (0|1) then i@source
((i-1)@makeProc(^&current) + (i-2)@makeProc(^&current)) @ source
}}
end