aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-08 17:53:56 +0100
committerGitHub <noreply@github.com>2025-09-08 17:53:56 +0100
commit44a60d838c321b35d403b8dd6bc1231e96ba7f15 (patch)
tree321348ae5d70127c86c1481c467b3b32f69d1084
parentc756218f390308804260ef50831d3ce38bc55df2 (diff)
parent11dd9990326da4ffa9d765d80148f8fe6e9cae65 (diff)
downloadperlweeklychallenge-club-44a60d838c321b35d403b8dd6bc1231e96ba7f15.tar.gz
perlweeklychallenge-club-44a60d838c321b35d403b8dd6bc1231e96ba7f15.tar.bz2
perlweeklychallenge-club-44a60d838c321b35d403b8dd6bc1231e96ba7f15.zip
Merge pull request #12645 from choroba/ech338
Add solutions to 338: Highest Row & Max Distance by E. Choroba
-rwxr-xr-xchallenge-338/e-choroba/perl/ch-1.pl37
-rwxr-xr-xchallenge-338/e-choroba/perl/ch-2.pl18
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-338/e-choroba/perl/ch-1.pl b/challenge-338/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..7a8dac4534
--- /dev/null
+++ b/challenge-338/e-choroba/perl/ch-1.pl
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use PDL;
+
+sub highest_row(@matrix) {
+ return pdl(@matrix)->sumover->max
+}
+
+use Test::More tests => 5;
+
+is highest_row([4, 4, 4, 4],
+ [10, 0, 0, 0],
+ [2, 2, 2, 9]),
+ 16, 'Example 1';
+
+is highest_row([1, 5],
+ [7, 3],
+ [3, 5]),
+ '10', 'Example 2';
+
+is highest_row([1, 2, 3],
+ [3, 2, 1]),
+ 6, 'Example 3';
+
+is highest_row([2, 8, 7],
+ [7, 1, 3],
+ [1, 9, 5]),
+ '17', 'Example 4';
+
+is highest_row([10, 20, 30],
+ [5, 5, 5],
+ [0, 100, 0],
+ [25, 25, 25]),
+ 100, 'Example 5';
diff --git a/challenge-338/e-choroba/perl/ch-2.pl b/challenge-338/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..1a558fdaed
--- /dev/null
+++ b/challenge-338/e-choroba/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use List::Util qw{ max min };
+
+sub max_distance($arr1, $arr2) {
+ return max(max(@$arr1) - min(@$arr2), max(@$arr2) - min(@$arr1))
+}
+
+use Test::More tests => 5;
+
+is max_distance([4, 5, 7], [9, 1, 3, 4]), 6, 'Example 1';
+is max_distance([2, 3, 5, 4], [3, 2, 5, 5, 8, 7]), 6, 'Example 2';
+is max_distance([2, 1, 11, 3], [2, 5, 10, 2]), 9, 'Example 3';
+is max_distance([1, 2, 3], [3, 2, 1]), 2, 'Example 4';
+is max_distance([1, 0, 2, 3], [5, 0]), 5, 'Example 5';