Skip to content

Instantly share code, notes, and snippets.

@adam000
Last active December 26, 2015 22:39
Show Gist options
  • Save adam000/7224933 to your computer and use it in GitHub Desktop.
Save adam000/7224933 to your computer and use it in GitHub Desktop.
I'm not sure what this is, but I found it floating around on my computer. It seems to be doing some sort of permutation-like logic.
It seems to be following some permutation-like math:
trees[2] = trees[0]*trees[1] + trees[1]*trees[0]
trees[3] = trees[0]*trees[2] + trees[1]*trees[1] + trees[2]*trees[0]
trees[4] = trees[0]*trees[3] + trees[1]*trees[2] + trees[2]*trees[1] + trees[3]*trees[0]
etc.
I would love to know why it is doing this, but alas, I cannot remember.
-- Interesting metatable implementation for a problem I had on some final or other, but we had to implement it in Java :[
trees = { [0] = 1, [1] = 1 }
setmetatable(trees, {
__index = function(table, i)
local sum = 0
for j = 0, i - 1 do
sum = sum + table[j] * table[i - 1 - j]
end
table[i] = sum
return sum
end })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment