aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-268/robbie-hatley/perl/ch-1.pl44
-rwxr-xr-xchallenge-268/robbie-hatley/perl/ch-2.pl29
2 files changed, 34 insertions, 39 deletions
diff --git a/challenge-268/robbie-hatley/perl/ch-1.pl b/challenge-268/robbie-hatley/perl/ch-1.pl
index 82efc9d48b..73353171fb 100755
--- a/challenge-268/robbie-hatley/perl/ch-1.pl
+++ b/challenge-268/robbie-hatley/perl/ch-1.pl
@@ -65,31 +65,31 @@ Output is to STDOUT and will be each input followed by the corresponding output.
# ------------------------------------------------------------------------------------------------------------
# PRAGMAS, MODULES, AND SUBS:
-use v5.38;
-use List::MoreUtils 'zip6';
-use List::Util 'all';
-
-# Is a given scalar a reference to a Pair Of Same-Size Arrays Of Numbers?
-sub is_possaon ($matref) {
- 'ARRAY' ne ref $matref and return 0;
- 2 != scalar(@$matref) and return 0;
- scalar(@{$$matref[0]}) != scalar(@{$$matref[1]}) and return 0;
- for my $rowref (@$matref) {
- for my $element (@$rowref) {
- $element !~ m/^-[1-9]\d*$|^0$|^[1-9]\d*$/ and return 0;
+ use v5.38;
+ use List::MoreUtils 'zip6';
+ use List::Util 'all';
+
+ # Is a given scalar a reference to a Pair Of Same-Size Arrays Of Numbers?
+ sub is_possaon ($matref) {
+ 'ARRAY' ne ref $matref and return 0;
+ 2 != scalar(@$matref) and return 0;
+ scalar(@{$$matref[0]}) != scalar(@{$$matref[1]}) and return 0;
+ for my $rowref (@$matref) {
+ for my $element (@$rowref) {
+ $element !~ m/^-[1-9]\d*$|^0$|^[1-9]\d*$/ and return 0;
+ }
}
+ return 1;
}
- 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]};
- my @diff = map {$$_[1]-$$_[0]} zip6 @row1, @row2;
- all {$diff[0] == $_} @diff and return $diff[0]
- or return 'none';
-}
+ # 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]};
+ my @diff = map {$$_[1]-$$_[0]} zip6 @row1, @row2;
+ all {$diff[0] == $_} @diff and return $diff[0]
+ or return 'none';
+ }
# ------------------------------------------------------------------------------------------------------------
# INPUTS:
diff --git a/challenge-268/robbie-hatley/perl/ch-2.pl b/challenge-268/robbie-hatley/perl/ch-2.pl
index a48e66a289..690d1bb287 100755
--- a/challenge-268/robbie-hatley/perl/ch-2.pl
+++ b/challenge-268/robbie-hatley/perl/ch-2.pl
@@ -60,27 +60,22 @@ Output is to STDOUT and will be each input followed by the corresponding output.
# ------------------------------------------------------------------------------------------------------------
# PRAGMAS, MODULES, AND SUBS:
-use v5.38;
+ use v5.38;
-# Is a given scalar a reference to an Array Of Integers?
-sub is_aoi ($aref) {
- 'ARRAY' ne ref $aref and return 0;
- for my $x (@$aref) {
- $x !~ m/^-[1-9]\d*$|^0$|^[1-9]\d*$/ and return 0;
+ # Is a given scalar a reference to an Array Of Integers?
+ sub is_aoi ($aref) {
+ 'ARRAY' ne ref $aref and return 0;
+ for my $x (@$aref) {
+ $x !~ m/^-[1-9]\d*$|^0$|^[1-9]\d*$/ and return 0;
+ }
+ return 1;
}
- return 1;
-}
-# Reorder array of ints into a zigzagging ascending stairway:
-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;
+ # Reorder array of ints into a zigzagging ascending stairway:
+ sub stairway (@array) {
+ my @sorted = sort {$a<=>$b} @array;
+ map {@sorted[2*$_+1,2*$_]} 0..($#sorted-1)/2;
}
- return @zigzag;
-}
# ------------------------------------------------------------------------------------------------------------
# INPUTS: