aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobbie-hatley <Robbie.Hatley@gmail.com>2024-05-11 13:23:45 -0700
committerrobbie-hatley <Robbie.Hatley@gmail.com>2024-05-11 13:23:45 -0700
commit2749df1c1b82cd174f3676c083418f2c8e8f8f8c (patch)
treeb1715334d0f8e845e0b469bf662f3afffdb72e7d
parente5f3bc7f1000e693e2f8eefc59b802dfb559a442 (diff)
downloadperlweeklychallenge-club-2749df1c1b82cd174f3676c083418f2c8e8f8f8c.tar.gz
perlweeklychallenge-club-2749df1c1b82cd174f3676c083418f2c8e8f8f8c.tar.bz2
perlweeklychallenge-club-2749df1c1b82cd174f3676c083418f2c8e8f8f8c.zip
Some error corrections for Robbie Hatley's Perl solutions for The Weekly Challenge #268.
-rwxr-xr-xchallenge-268/robbie-hatley/perl/ch-1.pl4
-rwxr-xr-xchallenge-268/robbie-hatley/perl/ch-2.pl12
2 files changed, 5 insertions, 11 deletions
diff --git a/challenge-268/robbie-hatley/perl/ch-1.pl b/challenge-268/robbie-hatley/perl/ch-1.pl
index ccf51e42d6..8060986d2b 100755
--- a/challenge-268/robbie-hatley/perl/ch-1.pl
+++ b/challenge-268/robbie-hatley/perl/ch-1.pl
@@ -47,8 +47,8 @@ that common value is our "magic number", otherwise return "none":
sub magic ($matref) {
my @row1 = sort {$a<=>$b} @{$$matref[0]};
my @row2 = sort {$a<=>$b} @{$$matref[1]};
- my @diff = map {$$_[1]-$$_[0]} zip6 @row1, @row2;
- all {$diff[0] == $_} @diff and return $diff[0]
+ my @diff = pairwise {$b-$a} @row1, @row2;
+ all {$_ == $diff[0]} @diff and return $diff[0]
or return 'none';
}
diff --git a/challenge-268/robbie-hatley/perl/ch-2.pl b/challenge-268/robbie-hatley/perl/ch-2.pl
index 2e59faae33..a882accdce 100755
--- a/challenge-268/robbie-hatley/perl/ch-2.pl
+++ b/challenge-268/robbie-hatley/perl/ch-2.pl
@@ -34,17 +34,11 @@ Output: (2, 1, 3, 2)
--------------------------------------------------------------------------------------------------------------
PROBLEM NOTES:
-This is equivalent to first sorting each array in increasing numeric order ("sort {$a<=>$b} @array"), then
-swapping pairs. Something like this:
+This is equivalent to first sorting each array in increasing numeric order ("sort {$a<=>$b} @array"),
+then swapping pairs:
sub stairway (@array) {
- my @zigzag = sort {$a<=>$b} @array;
- for ( my $i = 0 ; $i <= $#zigzag - 1 ; $i += 2 ) {
- my $temp = $zigzag[$i];
- $zigzag[$i] = $zigzag[$i+1];
- $zigzag[$i+1] = $temp;
- }
- return @zigzag;
+ pairmap {$b,$a} sort {$a<=>$b} @array;
}
--------------------------------------------------------------------------------------------------------------