-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree.lua
More file actions
51 lines (43 loc) · 1.23 KB
/
tree.lua
File metadata and controls
51 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local function BottomUpTree(depth)
if depth > 0 then
depth = depth - 1
local left, right = BottomUpTree(depth), BottomUpTree(depth)
return {left, right}
else
return {}
end
end
local function ItemCheck(tree)
if tree[1] then
return 1 + ItemCheck(tree[1]) + ItemCheck(tree[2])
else
return 1
end
end
local function tree(N)
if (N < 0) then
return 0
end
local mindepth = 4
local maxdepth = mindepth + 2
if maxdepth < N then
maxdepth = N
end
local stretchdepth = maxdepth + 1
local stretchtree = BottomUpTree(stretchdepth)
ItemCheck(stretchtree)
local longlivedtree = BottomUpTree(maxdepth)
local mmd = maxdepth + mindepth
for depth = mindepth, maxdepth, 2 do
local iterations = 2 ^ (mmd - depth)
local check = 0
for i = 1, iterations do
check = check + ItemCheck(BottomUpTree(depth))
end
end
ItemCheck(longlivedtree)
return 0
end
function Test(N)
return tree(N)
end