aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2025-09-08 07:13:54 +0000
committerNiels van Dijke <perlboy@cpan.org>2025-09-08 07:13:54 +0000
commit5999e5a20b3241cb5459ce9b92497946d4eddf3d (patch)
tree3de0756d76f7a2e884e2152d08dd1d29fd259749
parent12d9b7370121f12b601562856772ed3c03f7bb94 (diff)
downloadperlweeklychallenge-club-5999e5a20b3241cb5459ce9b92497946d4eddf3d.tar.gz
perlweeklychallenge-club-5999e5a20b3241cb5459ce9b92497946d4eddf3d.tar.bz2
perlweeklychallenge-club-5999e5a20b3241cb5459ce9b92497946d4eddf3d.zip
w338 - Task 1 & 2
-rwxr-xr-xchallenge-338/perlboy1967/perl/ch1.pl33
-rwxr-xr-xchallenge-338/perlboy1967/perl/ch2.pl36
2 files changed, 69 insertions, 0 deletions
diff --git a/challenge-338/perlboy1967/perl/ch1.pl b/challenge-338/perlboy1967/perl/ch1.pl
new file mode 100755
index 0000000000..9b06e473db
--- /dev/null
+++ b/challenge-338/perlboy1967/perl/ch1.pl
@@ -0,0 +1,33 @@
+#!/bin/perl
+
+=pod
+
+L<https://theweeklychallenge.org/blog/perl-weekly-challenge-338#TASK1>
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Highest Row
+Submitted by: Mohammad Sajid Anwar
+
+You are given a m x n matrix.
+
+Write a script to find the highest row sum in the given matrix.
+
+=cut
+
+use Test2::V0 qw(-no_srand);
+use exact 'v5.32', -signatures;
+
+use List::Util (qw(max sum));
+
+sub highestRow (@matrix) {
+ max map { sum @$_ } @matrix;
+}
+
+is(highestRow([4,4,4,4],[10,0,0,0],[2,2,2,9]),16,'Example 1');
+is(highestRow([1,5],[7,3],[3,5]),10,'Example 2');
+is(highestRow([1,2,3],[3,2,1]),6,'Example 3');
+is(highestRow([2,8,7],[7,1,3],[1,9,5]),17,'Example 4');
+is(highestRow([10,20,40],[5,5,5,],[0,100,0],[25,25,25]),100,'Example 5');
+
+done_testing;
diff --git a/challenge-338/perlboy1967/perl/ch2.pl b/challenge-338/perlboy1967/perl/ch2.pl
new file mode 100755
index 0000000000..af18fbad8d
--- /dev/null
+++ b/challenge-338/perlboy1967/perl/ch2.pl
@@ -0,0 +1,36 @@
+#!/bin/perl
+
+=pod
+
+L<https://theweeklychallenge.org/blog/perl-weekly-challenge-338#TASK2>
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Max Distance
+Submitted by: Mohammad Sajid Anwar
+
+You are given two integer arrays, @arr1 and @arr2.
+
+Write a script to find the maximum difference between any pair of values from both arrays.
+
+=cut
+
+use Test2::V0 qw(-no_srand);
+use exact 'v5.32', -signatures;
+
+use List::Util qw(max);
+
+sub maxDistance ($arM1,$arM2) {
+ max map {
+ my $i = $_;
+ map { abs($i-$_) } @$arM2
+ } @$arM1;
+}
+
+is(maxDistance([4,5,7],[9,1,3,4]),6,'Example 1');
+is(maxDistance([2,3,5,4],[3,2,5,5,8,7]),6,'Example 2');
+is(maxDistance([2,1,11,3],[2,5,10,2]),9,'Example 3');
+is(maxDistance([1,2,3],[3,2,1]),2,'Example 4');
+is(maxDistance([1,0,2,3],[5,0]),5,'Example 5');
+
+done_testing;