aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
}
--------------------------------------------------------------------------------------------------------------