Skip to content

Instantly share code, notes, and snippets.

@moleike
Created June 5, 2021 02:15
Show Gist options
  • Save moleike/5bf179767fdb3ea6f8a54489a0a06f31 to your computer and use it in GitHub Desktop.
Save moleike/5bf179767fdb3ea6f8a54489a0a06f31 to your computer and use it in GitHub Desktop.
// a memoized fibonnaci using field caching
local fib(n) =
local go(n) =
if n <= 1 then
{ ['fib0']: 1, ['fib1']: 1 }
else
go(n - 1) {
['fib'+n]: super['fib'+(n-1)] + super['fib'+(n-2)]
};
go(n)['fib'+n];
fib(25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment