Last active
December 26, 2015 22:39
-
-
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.
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
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. |
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
-- 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