diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-09-08 09:08:07 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-08 09:08:07 +0100 |
| commit | d3703790885c7629c2546e8fd1b71a2d52e593dc (patch) | |
| tree | 0a337326313161915ecffbb6190246e7f845fa9f | |
| parent | 6aca42494cd9799fc1b0404bbc1040b39a69f18d (diff) | |
| parent | 5999e5a20b3241cb5459ce9b92497946d4eddf3d (diff) | |
| download | perlweeklychallenge-club-d3703790885c7629c2546e8fd1b71a2d52e593dc.tar.gz perlweeklychallenge-club-d3703790885c7629c2546e8fd1b71a2d52e593dc.tar.bz2 perlweeklychallenge-club-d3703790885c7629c2546e8fd1b71a2d52e593dc.zip | |
Merge pull request #12642 from PerlBoy1967/branch-for-challenge-338
w338 - Task 1 & 2
| -rwxr-xr-x | challenge-338/perlboy1967/perl/ch1.pl | 33 | ||||
| -rwxr-xr-x | challenge-338/perlboy1967/perl/ch2.pl | 36 |
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; |
