diff options
| author | robbie-hatley <Hatley.Software@gmail.com> | 2024-05-10 09:38:07 -0700 |
|---|---|---|
| committer | robbie-hatley <Hatley.Software@gmail.com> | 2024-05-10 09:38:07 -0700 |
| commit | 2cf5836157d13cfc2cf0d3d99b8a063a108342d5 (patch) | |
| tree | 88c021d915ac1737abc4d90a7d3d8db966cd42f0 | |
| parent | 6520342720d049560b6ae78fa41e6d23016308a8 (diff) | |
| download | perlweeklychallenge-club-2cf5836157d13cfc2cf0d3d99b8a063a108342d5.tar.gz perlweeklychallenge-club-2cf5836157d13cfc2cf0d3d99b8a063a108342d5.tar.bz2 perlweeklychallenge-club-2cf5836157d13cfc2cf0d3d99b8a063a108342d5.zip | |
Changes to my Perl solutions to PWCC 268 from work, 2024-05-10_09-38.
| -rwxr-xr-x | challenge-268/robbie-hatley/perl/ch-1.pl | 1 | ||||
| -rwxr-xr-x | challenge-268/robbie-hatley/perl/ch-2.pl | 10 |
2 files changed, 4 insertions, 7 deletions
diff --git a/challenge-268/robbie-hatley/perl/ch-1.pl b/challenge-268/robbie-hatley/perl/ch-1.pl index 73353171fb..5f7860b760 100755 --- a/challenge-268/robbie-hatley/perl/ch-1.pl +++ b/challenge-268/robbie-hatley/perl/ch-1.pl @@ -44,6 +44,7 @@ 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": + # 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 690d1bb287..a97e2828e0 100755 --- a/challenge-268/robbie-hatley/perl/ch-2.pl +++ b/challenge-268/robbie-hatley/perl/ch-2.pl @@ -37,14 +37,10 @@ PROBLEM NOTES: This is equivalent to first sorting each array in increasing numeric order ("sort {$a<=>$b} @array"), then swapping pairs. Something like this: + # 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; - } - return @zigzag; + my @sorted = sort {$a<=>$b} @array; + map {@sorted[2*$_+1,2*$_]} 0..($#sorted-1)/2; } -------------------------------------------------------------------------------------------------------------- |
