Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
18
Task/Fibonacci-sequence/Phix/fibonacci-sequence-1.phix
Normal file
18
Task/Fibonacci-sequence/Phix/fibonacci-sequence-1.phix
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
sequence fcache = {1,1}
|
||||
|
||||
function fibonamem(integer n) -- memoized, works for -ve numbers, inaccurate above 78
|
||||
integer absn = abs(n)
|
||||
if n=0 then return 0 end if
|
||||
if absn>length(fcache) then
|
||||
fcache = append(fcache,fibonamem(absn-1)+fibonamem(absn-2))
|
||||
if absn!=length(fcache) then ?9/0 end if
|
||||
end if
|
||||
if n<0 and remainder(n,2)=0 then return -fcache[absn] end if
|
||||
return fcache[absn]
|
||||
end function
|
||||
|
||||
for i=0 to 30 do
|
||||
printf(1,"%d", fibonamem(i))
|
||||
if i!=30 then puts(1,", ") end if
|
||||
end for
|
||||
puts(1,"\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue