From 4699f600935129b16a48074d8534411ce935db17 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 3 Jan 2022 12:25:51 +0100 Subject: Week 146 Part 1 is a fixed output challenge, so, just a glorified Hello World program. It's stolen from project Euler, task 7. --- challenge-146/abigail/lua/ch-1.lua | 11 +++++++++++ challenge-146/abigail/lua/ch-2.lua | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 challenge-146/abigail/lua/ch-1.lua create mode 100644 challenge-146/abigail/lua/ch-2.lua (limited to 'challenge-146/abigail/lua') diff --git a/challenge-146/abigail/lua/ch-1.lua b/challenge-146/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..563c4fbf4b --- /dev/null +++ b/challenge-146/abigail/lua/ch-1.lua @@ -0,0 +1,11 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua +-- + +print ("104743") \ No newline at end of file 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 -- cgit