Comment by mjmas
2 months ago
function fib(a)
return countfib(1,1,a)
end
function countfib(a,b,n)
if n == 1 then
return a
else
-- proper tail call
return countfib(b,a+b,n-1)
end
end
print(fib(6)) --> 8
2 months ago
function fib(a)
return countfib(1,1,a)
end
function countfib(a,b,n)
if n == 1 then
return a
else
-- proper tail call
return countfib(b,a+b,n-1)
end
end
print(fib(6)) --> 8
No comments yet
Contribute on Hacker News ↗