blob: 1d8664060ff58f2de8824bcce9a7e6f9f09b0004 (
plain)
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
|
#!/opt/local/bin/lua
--
-- See https://theweeklychallenge.org/blog/perl-weekly-challenge-151
--
--
-- Run as: lua ch-1.lua < input-file
--
for line in io . lines () do
local tree = {}
local d = 1
local i = 1
tree [d] = {}
for token in line : gmatch ("(%S+)") do
if token == "|" then
d = d + 1
i = 1
tree [d] = {}
goto end_loop
end
if token == "*" then
i = i + 1
goto end_loop
end
tree [d] [i] = 1
i = i + 1
::end_loop::
end
for d, row in ipairs (tree) do
for i, _ in pairs (row) do
if not tree [d + 1] or
not tree [d + 1] [2 * i - 1] and not tree [d + 1] [2 * i] then
print (d)
goto end_main
end
end
end
::end_main::
end
|