Skip to content

Instantly share code, notes, and snippets.

@TannerRogalsky
Created July 24, 2012 15:36
Show Gist options
  • Save TannerRogalsky/3170712 to your computer and use it in GitHub Desktop.
Save TannerRogalsky/3170712 to your computer and use it in GitHub Desktop.
Auto-memoizing Fibonacci sequence in lua metatables
fib = setmetatable({1, 1},
{__index = function(t,n)
t[n] = t[n-1] + t[n-2]
return t[n]
end})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment