aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobbie-hatley <Robbie.Hatley@gmail.com>2024-05-08 19:46:55 -0700
committerrobbie-hatley <Robbie.Hatley@gmail.com>2024-05-08 19:46:55 -0700
commit8a3c6cf93015da059f25c462cd2d0dc98c35305b (patch)
tree793e0dd51da3efb3e14f96a979626e1f391efddf
parent1e4191cece0997f12dd8acba835c0af15fdbf140 (diff)
downloadperlweeklychallenge-club-8a3c6cf93015da059f25c462cd2d0dc98c35305b.tar.gz
perlweeklychallenge-club-8a3c6cf93015da059f25c462cd2d0dc98c35305b.tar.bz2
perlweeklychallenge-club-8a3c6cf93015da059f25c462cd2d0dc98c35305b.zip
Updates to my solutions to PWCC 268.
-rwxr-xr-xchallenge-268/robbie-hatley/perl/ch-1.pl15
-rwxr-xr-xchallenge-268/robbie-hatley/perl/ch-2.pl16
2 files changed, 16 insertions, 15 deletions
diff --git a/challenge-268/robbie-hatley/perl/ch-1.pl b/challenge-268/robbie-hatley/perl/ch-1.pl
index f597ebc58b..82efc9d48b 100755
--- a/challenge-268/robbie-hatley/perl/ch-1.pl
+++ b/challenge-268/robbie-hatley/perl/ch-1.pl
@@ -44,13 +44,13 @@ PROBLEM NOTES:
I'll sort both arrays then subtract the second from the first. If all elements of the difference are the same,
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]
- or 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]
+ or return 'none';
+ }
--------------------------------------------------------------------------------------------------------------
IO NOTES:
@@ -82,6 +82,7 @@ sub is_possaon ($matref) {
return 1;
}
+# Determine "magic number" (if any) for given matrix:
sub magic ($matref) {
my @row1 = sort {$a<=>$b} @{$$matref[0]};
my @row2 = sort {$a<=>$b} @{$$matref[1]};
diff --git a/challenge-268/robbie-hatley/perl/ch-2.pl b/challenge-268/robbie-hatley/perl/ch-2.pl
index 4bb77dc174..a48e66a289 100755
--- a/challenge-268/robbie-hatley/perl/ch-2.pl
+++ b/challenge-268/robbie-hatley/perl/ch-2.pl
@@ -37,15 +37,15 @@ PROBLEM NOTES:
This is equivalent to first sorting each array in increasing numeric order ("sort {$a<=>$b} @array"), then
swapping pairs. Something like this:
-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;
+ 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;
}
- return @zigzag;
-}
--------------------------------------------------------------------------------------------------------------
IO NOTES: