aboutsummaryrefslogtreecommitdiff
path: root/challenge-116/abigail/lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-116/abigail/lua')
-rw-r--r--challenge-116/abigail/lua/ch-1.lua39
-rw-r--r--challenge-116/abigail/lua/ch-2.lua22
2 files changed, 61 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..fadad776fa
--- /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_sequence (string, start)
+ if string == start
+ then return start
+ end
+ if string : find ("^" .. start)
+ then tail = string : sub (#start + 1, -1)
+ result = make_sequence (tail, tostring (tonumber (start) + 1))
+ if result ~= nil
+ then return start .. "," .. result
+ end
+ result = make_sequence (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_sequence (line, start)
+ if result ~= nil
+ then print (result)
+ goto end_main
+ end
+ end
+ ::end_main::
+end
diff --git a/challenge-116/abigail/lua/ch-2.lua b/challenge-116/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..f53ea72076
--- /dev/null
+++ b/challenge-116/abigail/lua/ch-2.lua
@@ -0,0 +1,22 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+for line in io . lines () do
+ local sum_of_squares = 0
+ for d in line : gmatch ("%d") do
+ local number = tonumber (d)
+ sum_of_squares = sum_of_squares + number * number
+ end
+ root = math . floor (.5 + math . sqrt (sum_of_squares))
+ if sum_of_squares == root * root
+ then print (1)
+ else print (0)
+ end
+end