aboutsummaryrefslogtreecommitdiff
path: root/challenge-151/abigail/lua/ch-1.lua
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2022-02-10 17:28:53 +0800
committer冯昶 <seaker@qq.com>2022-02-10 17:28:53 +0800
commit24d07638f45f70838ba3721106c5c4f6d992f69e (patch)
tree618c14fbb4615765f95353129863d3ad85a88867 /challenge-151/abigail/lua/ch-1.lua
parent1ff224c623b04c549b24ec402ea43131cd910588 (diff)
parentaf7e6f300ff3d68b38412f2be2a4fc845ae19a79 (diff)
downloadperlweeklychallenge-club-24d07638f45f70838ba3721106c5c4f6d992f69e.tar.gz
perlweeklychallenge-club-24d07638f45f70838ba3721106c5c4f6d992f69e.tar.bz2
perlweeklychallenge-club-24d07638f45f70838ba3721106c5c4f6d992f69e.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-151/abigail/lua/ch-1.lua')
-rw-r--r--challenge-151/abigail/lua/ch-1.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-151/abigail/lua/ch-1.lua b/challenge-151/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..1d8664060f
--- /dev/null
+++ b/challenge-151/abigail/lua/ch-1.lua
@@ -0,0 +1,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