Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Anonymous-recursion/Icon/anonymous-recursion-1.icon
Normal file
24
Task/Anonymous-recursion/Icon/anonymous-recursion-1.icon
Normal 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(^¤t)+(i-2)@makeProc(^¤t)) # 2
|
||||
cache[i] @ source # 3
|
||||
}}
|
||||
end
|
||||
|
||||
procedure makeProc(A)
|
||||
A := if type(A) == "list" then A[1]
|
||||
return (@A, A) # prime and return
|
||||
end
|
||||
9
Task/Anonymous-recursion/Icon/anonymous-recursion-2.icon
Normal file
9
Task/Anonymous-recursion/Icon/anonymous-recursion-2.icon
Normal 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(^¤t) + (i-2)@makeProc(^¤t)) @ source
|
||||
}}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue