aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-10-18 23:44:35 +0200
committerAbigail <abigail@abigail.be>2021-10-18 23:44:35 +0200
commit6fbe2f4e31051b2ecc881d9f476c61fe08b5b43b (patch)
tree85e721fa420e7727450139b551e6320a15a9e1fc
parente87959f9cfc997d0b9c5e8c17293797aaaba8915 (diff)
downloadperlweeklychallenge-club-6fbe2f4e31051b2ecc881d9f476c61fe08b5b43b.tar.gz
perlweeklychallenge-club-6fbe2f4e31051b2ecc881d9f476c61fe08b5b43b.tar.bz2
perlweeklychallenge-club-6fbe2f4e31051b2ecc881d9f476c61fe08b5b43b.zip
Lua solutions for week 135
-rw-r--r--challenge-135/abigail/README.md2
-rw-r--r--challenge-135/abigail/lua/ch-1.lua27
-rw-r--r--challenge-135/abigail/lua/ch-2.lua31
3 files changed, 60 insertions, 0 deletions
diff --git a/challenge-135/abigail/README.md b/challenge-135/abigail/README.md
index 1e8d468c68..9f6cb7b1ff 100644
--- a/challenge-135/abigail/README.md
+++ b/challenge-135/abigail/README.md
@@ -5,6 +5,7 @@
* [AWK](awk/ch-1.awk)
* [Bash](bash/ch-1.sh)
* [C](c/ch-1.c)
+* [Lua](lua/ch-1.lua)
* [Node.js](node/ch-1.js)
* [Perl](perl/ch-1.pl)
@@ -13,5 +14,6 @@
* [AWK](awk/ch-2.awk)
* [Bash](bash/ch-2.sh)
* [C](c/ch-2.c)
+* [Lua](lua/ch-2.lua)
* [Node.js](node/ch-2.js)
* [Perl](perl/ch-2.pl)
diff --git a/challenge-135/abigail/lua/ch-1.lua b/challenge-135/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..b5db984457
--- /dev/null
+++ b/challenge-135/abigail/lua/ch-1.lua
@@ -0,0 +1,27 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+for line in io . lines () do
+ line = line : gsub ("^[-+]%s*", "")
+ if line : find ("%D") then
+ print ("not an integer")
+ else
+ if line : len () % 2 == 0 then
+ print ("even number of digits")
+ else
+ if line : len () < 3 then
+ print ("too short")
+ else
+ local start = 1 + (line : len () - 3) / 2
+ print (line : sub (start , start + 2))
+ end
+ end
+ end
+end
diff --git a/challenge-135/abigail/lua/ch-2.lua b/challenge-135/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..e6b70b2830
--- /dev/null
+++ b/challenge-135/abigail/lua/ch-2.lua
@@ -0,0 +1,31 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+local w = {1, 3, 1, 7, 3, 9, 1}
+
+for line in io . lines () do
+ if line : find ("^[0-9BCDFGHJKLMNPQRSTVWXYZ]*$") then
+ local check = 0
+ for i = 1, 7 do
+ local byte = string . byte (line : sub (i, i))
+ if byte <= string . byte ("9")
+ then byte = byte - string . byte ("0")
+ else byte = byte - string . byte ("A") + 10
+ end
+ check = check + w [i] * byte
+ end
+ if check % 10 == 0
+ then print (1)
+ else print (0)
+ end
+ else
+ print (0)
+ end
+end