lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Rici Lake wrote:

Fib = Memoise(function(n)
  return Fib(n-1) + Fib(n-2)
Fib[1] = 1
Fib[2] = 1

= Fib[200]

The definition of Memoise I use has been left abandoned on the Lua Wiki
at since January 17, 2003 :) so I
won't bother repeating it here.

By the way, the above example won't work with values larger than
200 unless you recompile Lua with a larger C recursion limit
(LUAI_MAXCCALLS in luaconf.h)

Alternatively, you could do something like this:

for i = 100,1500,100 do print(Fib[i]) end

No overflow here!