From 23b2fd7bb31c97cd99ae62dc522a7607fcc2a297 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 19 May 2021 18:44:56 +0200 Subject: Lua solutions for week 113 --- challenge-113/abigail/lua/ch-2.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-113/abigail/lua/ch-2.lua (limited to 'challenge-113/abigail/lua/ch-2.lua') diff --git a/challenge-113/abigail/lua/ch-2.lua b/challenge-113/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..15aac1ac2d --- /dev/null +++ b/challenge-113/abigail/lua/ch-2.lua @@ -0,0 +1,25 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +for line in io . lines () do + local sum = 0 + for n in line : gmatch ("[0-9]+") + do sum = sum + tonumber (n) + end + local c = 0 + for n in line : gmatch ("[0-9]+") + do if c > 0 + then io . write (" ") + end + c = c + 1 + io . write (sum - n) + end + io . write ("\n") +end -- cgit From 2eedf165fbeb5289fea6c43fbe55b47a0d1ec8f8 Mon Sep 17 00:00:00 2001 From: Abigail Date: Wed, 19 May 2021 19:30:25 +0200 Subject: Allow negative numbers for week 113, part 2 (Perl, Lua) --- challenge-113/abigail/lua/ch-2.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'challenge-113/abigail/lua/ch-2.lua') diff --git a/challenge-113/abigail/lua/ch-2.lua b/challenge-113/abigail/lua/ch-2.lua index 15aac1ac2d..5ba4c04ed9 100644 --- a/challenge-113/abigail/lua/ch-2.lua +++ b/challenge-113/abigail/lua/ch-2.lua @@ -10,16 +10,16 @@ for line in io . lines () do local sum = 0 - for n in line : gmatch ("[0-9]+") + for n in line : gmatch ("-?[0-9]+") do sum = sum + tonumber (n) end local c = 0 - for n in line : gmatch ("[0-9]+") + for n in line : gmatch ("-?[0-9]+") do if c > 0 then io . write (" ") end c = c + 1 - io . write (sum - n) + io . write (sum - tonumber (n)) end io . write ("\n") end -- cgit