Created
July 24, 2012 15:36
-
-
Save TannerRogalsky/3170712 to your computer and use it in GitHub Desktop.
Auto-memoizing Fibonacci sequence in lua metatables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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