aboutsummaryrefslogtreecommitdiff
path: root/challenge-111/abigail
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-04 15:19:34 +0200
committerAbigail <abigail@abigail.be>2021-05-04 15:19:34 +0200
commit4ead8fc53f6cd3b29d00a1bc526d1754c03217d4 (patch)
treed906fda6df43dcdf0a11b8751a0ed15751f1abc7 /challenge-111/abigail
parent163c81d9189cd4ac1ac4a126763b7c889df8a6f7 (diff)
downloadperlweeklychallenge-club-4ead8fc53f6cd3b29d00a1bc526d1754c03217d4.tar.gz
perlweeklychallenge-club-4ead8fc53f6cd3b29d00a1bc526d1754c03217d4.tar.bz2
perlweeklychallenge-club-4ead8fc53f6cd3b29d00a1bc526d1754c03217d4.zip
Lua solution for week 111, part 1
Diffstat (limited to 'challenge-111/abigail')
-rw-r--r--challenge-111/abigail/README.md1
-rw-r--r--challenge-111/abigail/lua/ch-1.lua33
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md
index 92fe052262..bd9ef31d26 100644
--- a/challenge-111/abigail/README.md
+++ b/challenge-111/abigail/README.md
@@ -34,6 +34,7 @@ languages, the fact input is sorted does not offer additional benefits.
* [AWK](awk/ch-1.awk)
* [Bash](bash/ch-1.sh)
* [C](c/ch-1.c)
+* [Lua](lua/ch-1.lua)
* [Perl](perl/ch-1.pl)
### Blog
diff --git a/challenge-111/abigail/lua/ch-1.lua b/challenge-111/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..194e55b458
--- /dev/null
+++ b/challenge-111/abigail/lua/ch-1.lua
@@ -0,0 +1,33 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+local MATRIX_SIZE = 5
+
+matrix = {}
+
+--
+-- Read in the matrix
+--
+for i = 1, MATRIX_SIZE * MATRIX_SIZE do
+ matrix [io . read ("*number")] = 1
+end
+
+--
+-- Read in the rest, printing 1/0 depending on
+-- whether the number is present in the matrix or not.
+--
+while true do
+ target = io . read ("*number")
+ if target == nil then break end
+ if matrix [target]
+ then print (1)
+ else print (0)
+ end
+end