Slacker News Slacker News logo featuring a lazy sloth with a folded newspaper hat
  • top
  • new
  • show
  • ask
  • jobs
Library
← Back to context

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

0 comments

mjmas

Reply

No comments yet

Contribute on Hacker News ↗

Slacker News

Product

  • API Reference
  • Hacker News RSS
  • Source on GitHub

Community

  • Support Ukraine
  • Equal Justice Initiative
  • GiveWell Charities