diff options
| -rw-r--r-- | challenge-217/peter-campbell-smith/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-217/peter-campbell-smith/perl/ch-1.pl | 25 | ||||
| -rwxr-xr-x | challenge-217/peter-campbell-smith/perl/ch-2.pl | 20 |
3 files changed, 46 insertions, 0 deletions
diff --git a/challenge-217/peter-campbell-smith/blog.txt b/challenge-217/peter-campbell-smith/blog.txt new file mode 100644 index 0000000000..7259ed6378 --- /dev/null +++ b/challenge-217/peter-campbell-smith/blog.txt @@ -0,0 +1 @@ +http://ccgi.campbellsmiths.force9.co.uk/challenge/217 diff --git a/challenge-217/peter-campbell-smith/perl/ch-1.pl b/challenge-217/peter-campbell-smith/perl/ch-1.pl new file mode 100755 index 0000000000..0cb999c75b --- /dev/null +++ b/challenge-217/peter-campbell-smith/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use v5.16; # The Weekly Challenge - 2023-05-15 +use utf8; # Week 216 task 1 - Sorted matrix +use strict; # Peter Campbell Smith +use warnings; # Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge + +sorted_matrix([3, 1, 2], [5, 2, 4], [0, 1, 3]); +sorted_matrix([2, 1], [4, 5]); +sorted_matrix([1, 0, 3], [0, 0, 0], [1, 2, 1]); +sorted_matrix([1, 2, 3, 4, 5], [3, 4, 5, 6, 7], [9, 8, 7, 6, 5], [0, 2, 4, 6, 8], [9, 7, 5, 3, 1]); + +sub sorted_matrix { + + my (@list, @rows, $j); + + # concatenate rows and then sort the list + push @list, @$_ for @_; + @list = sort { $a <=> $b } @list; + + # show results + $rows[$j ++] = '[' . join(', ', @$_) . ']' for @_; + say qq[\nInput: \@matrix = (] . join(', ', @rows) . ')'; + say qq[Output: $list[2]]; +} diff --git a/challenge-217/peter-campbell-smith/perl/ch-2.pl b/challenge-217/peter-campbell-smith/perl/ch-2.pl new file mode 100755 index 0000000000..c9adadc632 --- /dev/null +++ b/challenge-217/peter-campbell-smith/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use v5.16; # The Weekly Challenge - 2023-05-15 +use utf8; # Week 216 task 1 - Max number +use strict; # Peter Campbell Smith +use warnings; # Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge + +max_number(1, 23); +max_number(10, 3, 2); +max_number(31, 2, 4, 10); +max_number(5, 11, 4, 1, 2); +max_number(1, 10); + +sub max_number { + + # concatenate the numbers in descending alphabetical sort order + say qq[\nInput: ] . join(', ', @_); + say qq[Output: ] . join('', reverse sort @_); +} + |
