aboutsummaryrefslogtreecommitdiff
path: root/challenge-118/abigail/lua
diff options
context:
space:
mode:
authorE7-87-83 <fungcheokyin@gmail.com>2021-07-04 22:18:36 +0800
committerE7-87-83 <fungcheokyin@gmail.com>2021-07-04 22:18:36 +0800
commit28eabc69c70046cc047e98e2b2987d71b4aae9fa (patch)
treef2fe2351445f68451ec14f21072719bc9db488b0 /challenge-118/abigail/lua
parentcdfef3f9404041b4c7936a26532757e63fd4fcef (diff)
parent5f7b76d5b841606c17f177a90397196ebf434c05 (diff)
downloadperlweeklychallenge-club-28eabc69c70046cc047e98e2b2987d71b4aae9fa.tar.gz
perlweeklychallenge-club-28eabc69c70046cc047e98e2b2987d71b4aae9fa.tar.bz2
perlweeklychallenge-club-28eabc69c70046cc047e98e2b2987d71b4aae9fa.zip
week 119
Diffstat (limited to 'challenge-118/abigail/lua')
-rw-r--r--challenge-118/abigail/lua/ch-1.lua32
-rw-r--r--challenge-118/abigail/lua/ch-2.lua11
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-118/abigail/lua/ch-1.lua b/challenge-118/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..a129db19e4
--- /dev/null
+++ b/challenge-118/abigail/lua/ch-1.lua
@@ -0,0 +1,32 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+--
+-- Find the binary representation of a number.
+-- Note that the function return a string in reverse order;
+-- this will do for our purpose as we want a palindrome anyway.
+--
+function dec2bin (dec)
+ local bin = {}
+ while dec > 0 do
+ bin [#bin + 1] = dec % 2
+ dec = math . floor (dec / 2)
+ end
+ return table . concat (bin)
+end
+
+for line in io . lines () do
+ bin = dec2bin (tonumber (line))
+ if bin == string . reverse (bin) then
+ print (1)
+ else
+ print (0)
+ end
+end
diff --git a/challenge-118/abigail/lua/ch-2.lua b/challenge-118/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..5c40dfc99c
--- /dev/null
+++ b/challenge-118/abigail/lua/ch-2.lua
@@ -0,0 +1,11 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua
+--
+
+print ("a8 c7 e6 c5 b3 c1 a2 c3 b1 a3 c4 b2")