aboutsummaryrefslogtreecommitdiff
path: root/challenge-102/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
authorboblied <boblied@gmail.com>2021-03-09 07:52:31 -0600
committerboblied <boblied@gmail.com>2021-03-09 07:52:31 -0600
commitc897ab614e0a35455865bfe930df300bb854a03b (patch)
treea6a3527b8364196045a94ab49661bd2eb9c8fea6 /challenge-102/abigail/lua/ch-2.lua
parent199d363b79e769bf8dc150bf37228395bfbb4d16 (diff)
parentda7e149ecb3abdf29d3fb4f712427217d02f2fe1 (diff)
downloadperlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.gz
perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.tar.bz2
perlweeklychallenge-club-c897ab614e0a35455865bfe930df300bb854a03b.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-102/abigail/lua/ch-2.lua')
-rw-r--r--challenge-102/abigail/lua/ch-2.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-102/abigail/lua/ch-2.lua b/challenge-102/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..bbeb2a13ae
--- /dev/null
+++ b/challenge-102/abigail/lua/ch-2.lua
@@ -0,0 +1,36 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+--
+-- Working from the end of the required string backwards, we alternate
+-- placing a hash, and placing a number. We place them in an array out,
+-- and at the end, print out said array in reverse order.
+--
+for index in io . lines () do
+ index = tonumber (index)
+ out = {}
+ hash = false
+ i = 0
+ while index > 0 do
+ hash = not hash
+ i = i + 1
+ if hash then
+ out [i] = "#"
+ index = index - 1
+ else
+ out [i] = index + 1
+ index = index - tostring (index + 1) : len ()
+ end
+ end
+ for j = i, 1, -1 do
+ io . write (out [j])
+ end
+ io . write ("\n")
+end