aboutsummaryrefslogtreecommitdiff
path: root/challenge-146/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-146/abigail/lua/ch-2.lua')
-rw-r--r--challenge-146/abigail/lua/ch-2.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-146/abigail/lua/ch-2.lua b/challenge-146/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..7429222642
--- /dev/null
+++ b/challenge-146/abigail/lua/ch-2.lua
@@ -0,0 +1,28 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+for line in io . lines () do
+ local _, _, a, b = line : find ("([0-9]+)/([0-9]+)")
+ a = tonumber (a)
+ b = tonumber (b)
+ for i = 1, 2 do
+ if a < b then
+ b = b - a
+ else
+ a = a - b
+ end
+ if a == 0 or b == 0 then
+ goto out_of_loop
+ end
+ io . write (a .. "/" .. b .. " ")
+ end
+ ::out_of_loop::
+ io . write ("\n")
+end