aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-05-19 19:30:25 +0200
committerAbigail <abigail@abigail.be>2021-05-19 19:30:25 +0200
commit2eedf165fbeb5289fea6c43fbe55b47a0d1ec8f8 (patch)
tree53da876ad204ba6d3d2a8f5909af04423d377048
parent98f821f841409373f067e0ed04629090a08ebb1f (diff)
downloadperlweeklychallenge-club-2eedf165fbeb5289fea6c43fbe55b47a0d1ec8f8.tar.gz
perlweeklychallenge-club-2eedf165fbeb5289fea6c43fbe55b47a0d1ec8f8.tar.bz2
perlweeklychallenge-club-2eedf165fbeb5289fea6c43fbe55b47a0d1ec8f8.zip
Allow negative numbers for week 113, part 2 (Perl, Lua)
-rw-r--r--challenge-113/abigail/lua/ch-2.lua6
-rw-r--r--challenge-113/abigail/perl/ch-1.pl2
-rw-r--r--challenge-113/abigail/perl/ch-2.pl4
3 files changed, 5 insertions, 7 deletions
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
diff --git a/challenge-113/abigail/perl/ch-1.pl b/challenge-113/abigail/perl/ch-1.pl
index 51a4842116..bb45261f33 100644
--- a/challenge-113/abigail/perl/ch-1.pl
+++ b/challenge-113/abigail/perl/ch-1.pl
@@ -70,8 +70,6 @@ use experimental 'lexical_subs';
#
# These are all the ls < $D so that $D does not divide 10 * l.
-my @l = ([], [], [1], [1 .. 2], [1],
- [], [1 .. 2], [1 .. 6], [1 .. 3], [1 .. 8]);
my @tens = (0, 0, 1, 2, 1, 0, 2, 6, 3, 8);
MAIN: while (<>) {
diff --git a/challenge-113/abigail/perl/ch-2.pl b/challenge-113/abigail/perl/ch-2.pl
index 4d7eeece79..7aabcc4b13 100644
--- a/challenge-113/abigail/perl/ch-2.pl
+++ b/challenge-113/abigail/perl/ch-2.pl
@@ -14,7 +14,7 @@ use experimental 'lexical_subs';
#
#
-# Run as: perl ch-1.pl < input-file
+# Run as: perl ch-2.pl < input-file
#
#
@@ -34,6 +34,6 @@ use experimental 'lexical_subs';
use List::Util qw [sum];
while (<>) {
- my $sum = sum my @num = /[0-9]+/g;
+ my $sum = sum my @num = /-?[0-9]+/g;
say join " " => map {$sum - $_} @num;
}