aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/lua
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-06-09 18:03:02 +0200
committerAbigail <abigail@abigail.be>2021-06-09 20:15:02 +0200
commit3fe9fba9c9d2ec298020988b59ddf16dade7285f (patch)
tree2c95969649117c985d1a5cc9c753be01abf32f29 /challenge-116/abigail/lua
parentef7ce9bd5bf986bd4f2d99e082013e5f895f0d9e (diff)
downloadperlweeklychallenge-club-3fe9fba9c9d2ec298020988b59ddf16dade7285f.tar.gz
perlweeklychallenge-club-3fe9fba9c9d2ec298020988b59ddf16dade7285f.tar.bz2
perlweeklychallenge-club-3fe9fba9c9d2ec298020988b59ddf16dade7285f.zip
AWK, Bash, Lua, Node.js, Perl, Python, Ruby solutions for week 116, part 1
Diffstat (limited to 'challenge-116/abigail/lua')
-rw-r--r--challenge-116/abigail/lua/ch-1.lua39
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-116/abigail/lua/ch-1.lua b/challenge-116/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..df551a2e46
--- /dev/null
+++ b/challenge-116/abigail/lua/ch-1.lua
@@ -0,0 +1,39 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua < input-file
+--
+
+function make_chain (string, start)
+ if string == start
+ then return start
+ end
+ if string : find ("^" .. start)
+ then tail = string : sub (#start + 1, -1)
+ result = make_chain (tail, tostring (tonumber (start) + 1))
+ if result ~= nil
+ then return start .. "," .. result
+ end
+ result = make_chain (tail, tostring (tonumber (start) - 1))
+ if result ~= nil
+ then return start .. "," .. result
+ end
+ end
+ return nil
+end
+
+for line in io . lines () do
+ for i = 1, #line do
+ start = line : sub (1, i)
+ result = make_chain (line, start)
+ if result ~= nil
+ then print (result)
+ goto end_main
+ end
+ end
+ ::end_main::
+end