diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-02-08 20:03:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-08 20:03:07 +0000 |
| commit | 9e8211950a93c9370824c4cd25092d2c72cef692 (patch) | |
| tree | b02229e447f129e60744b12f9872796e22e41c40 /challenge-151/abigail/lua/ch-1.lua | |
| parent | bdaaa49f20ca56057a3a478a383f0af2253f6f6b (diff) | |
| parent | a09d0dd70c22dc386c4280cfae04158098dcc924 (diff) | |
| download | perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.tar.gz perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.tar.bz2 perlweeklychallenge-club-9e8211950a93c9370824c4cd25092d2c72cef692.zip | |
Merge pull request #5629 from Abigail/abigail/week-151
Abigail/week 151
Diffstat (limited to 'challenge-151/abigail/lua/ch-1.lua')
| -rw-r--r-- | challenge-151/abigail/lua/ch-1.lua | 45 |
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 |
