-
Notifications
You must be signed in to change notification settings - Fork 0
/
asdf.lua
54 lines (46 loc) · 1.06 KB
/
asdf.lua
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
52
53
54
local cacheStep = {
{
"***",
"* *",
"***",
},
{
"*********",
"* ** ** *",
"*********",
"*** ***",
"* * * *",
"*** ***",
"*********",
"* ** ** *",
"*********",
}
}
local rep = string.rep
local concat = table.concat
local function buildStep(n)
if cacheStep[n] then return cacheStep[n] end
local child = cacheStep[n-1]
if not child then
child = buildStep(n-1)
end
local newStep = {}
local childSizeX = 3^(n-1)
local lastLineOffset = childSizeX*2
local space = rep(" ",childSizeX)
for i=1,childSizeX do
local line = child[i]
local lineRep = rep(line,3)
newStep[i] = lineRep
newStep[i+lastLineOffset] = lineRep
newStep[childSizeX+i] = concat(line,space,line)
end
cacheStep[n] = newStep
return newStep
end
local N = io.read'n'
local K = math.floor(math.log(N,3)+0.5)
-- for _,str in ipairs(buildStep(K)) do
-- print(str)
-- end
io.write(table.concat(buildStep(K),'\n'))