aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2023-05-22 21:42:43 +0000
committerNiels van Dijke <perlboy@cpan.org>2023-05-22 21:42:43 +0000
commitb9798d4f8d8d14c5230c442253ad52e6994da391 (patch)
tree170b4330fd7b3f62d48e15d544a82b212daede79
parent3eac84cedbe50a028765be18bf09465ad1edc539 (diff)
downloadperlweeklychallenge-club-b9798d4f8d8d14c5230c442253ad52e6994da391.tar.gz
perlweeklychallenge-club-b9798d4f8d8d14c5230c442253ad52e6994da391.tar.bz2
perlweeklychallenge-club-b9798d4f8d8d14c5230c442253ad52e6994da391.zip
Some comments
-rwxr-xr-xchallenge-218/perlboy1967/perl/ch1.pl3
-rwxr-xr-xchallenge-218/perlboy1967/perl/ch2.pl3
2 files changed, 5 insertions, 1 deletions
diff --git a/challenge-218/perlboy1967/perl/ch1.pl b/challenge-218/perlboy1967/perl/ch1.pl
index 79ef7e0701..48bbc2aa76 100755
--- a/challenge-218/perlboy1967/perl/ch1.pl
+++ b/challenge-218/perlboy1967/perl/ch1.pl
@@ -27,12 +27,15 @@ use Test::More;
sub maxProduct (@) {
my (@n,@p);
+ # Find negative and positive factors
for (@_) {
$_ < 0 ? push(@n,$_) :
$_ > 0 ? push(@p,$_) :
0;
}
+ # If we have an odd number of negative factors,
+ # ditch the one closest to zero
@n = sort {$a <=> $b} @n;
pop @n if (@n % 2);
diff --git a/challenge-218/perlboy1967/perl/ch2.pl b/challenge-218/perlboy1967/perl/ch2.pl
index 9eaefc1b60..757630f319 100755
--- a/challenge-218/perlboy1967/perl/ch2.pl
+++ b/challenge-218/perlboy1967/perl/ch2.pl
@@ -40,7 +40,8 @@ sub matrixScore (\@) {
for my $c (1 .. $nC) {
my $ones = grep { $ar->[$_][$c] == 1 } (0 .. $nR);
- # Flip bits in column C if number of '1's ir smaller than rows
+
+ # Flip bits in column C if number of '1's is smaller than # of rows
map { $ar->[$_][$c] = ++$$ar[$_][$c] % 2 } (0 .. $nR)
if ($ones < $nR);
}