diff options
| author | Abigail <abigail@abigail.freedom.nl> | 2022-02-07 22:37:05 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.freedom.nl> | 2022-02-07 22:37:05 +0100 |
| commit | f1bc02f8fcc156205b2a8ccabaf0063f32ab8106 (patch) | |
| tree | c1de78dd3162abbb01e3d729d006d0325cd75d99 /challenge-151/abigail/lua/ch-1.lua | |
| parent | e270077b999c4129874da382d77addc76460aa17 (diff) | |
| download | perlweeklychallenge-club-f1bc02f8fcc156205b2a8ccabaf0063f32ab8106.tar.gz perlweeklychallenge-club-f1bc02f8fcc156205b2a8ccabaf0063f32ab8106.tar.bz2 perlweeklychallenge-club-f1bc02f8fcc156205b2a8ccabaf0063f32ab8106.zip | |
Week 151: Lua solutions
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 |
