aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Mahnke <andreas.mahnke@leuphana.de>2025-09-08 14:32:56 +0200
committerAndreas Mahnke <andreas.mahnke@leuphana.de>2025-09-08 14:32:56 +0200
commitbd07161ddc27463cc143890ca64e7f15db1ad402 (patch)
treee6018b0e224f6b95a129e9dc806bfc13ba1e4cea
parentcb150b4089bfaa27339dfd6bb4e51b580b12c32b (diff)
downloadperlweeklychallenge-club-bd07161ddc27463cc143890ca64e7f15db1ad402.tar.gz
perlweeklychallenge-club-bd07161ddc27463cc143890ca64e7f15db1ad402.tar.bz2
perlweeklychallenge-club-bd07161ddc27463cc143890ca64e7f15db1ad402.zip
Challenge 338
-rw-r--r--challenge-338/mahnkong/perl/ch-1.pl20
-rw-r--r--challenge-338/mahnkong/perl/ch-2.pl20
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-338/mahnkong/perl/ch-1.pl b/challenge-338/mahnkong/perl/ch-1.pl
new file mode 100644
index 0000000000..fa0877befe
--- /dev/null
+++ b/challenge-338/mahnkong/perl/ch-1.pl
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run(@matrix) {
+ my $highest_sum;
+ foreach my $row (@matrix) {
+ my $sum = 0;
+ map { $sum += $_ } @$row;
+ $highest_sum = $sum if !defined $highest_sum || $sum > $highest_sum;
+ }
+ return $highest_sum;
+}
+
+is(run([4, 4, 4, 4], [10, 0, 0, 0], [2, 2, 2, 9]), 16, "Example 1");
+is(run([1, 5], [7, 3], [3, 5]), 10, "Example 2");
+is(run([1, 2, 3], [3, 2, 1]), 6, "Example 3");
+is(run([2, 8, 7], [7, 1, 3], [1, 9, 5]), 17, "Example 4");
+is(run([10, 20, 30], [5, 5, 5], [0, 100, 0], [25, 25, 25]), 100, "Example 5");
diff --git a/challenge-338/mahnkong/perl/ch-2.pl b/challenge-338/mahnkong/perl/ch-2.pl
new file mode 100644
index 0000000000..fc5003fa94
--- /dev/null
+++ b/challenge-338/mahnkong/perl/ch-2.pl
@@ -0,0 +1,20 @@
+use strict;
+use warnings;
+use feature 'signatures';
+use Test::More 'no_plan';
+
+sub run($arr1, $arr2) {
+ my @arr1 = sort {$a <=> $b} @$arr1;
+ my @arr2 = sort {$a <=> $b} @$arr2;
+
+ my $d1 = abs($arr1[0] - $arr2[-1]);
+ my $d2 = abs($arr2[0] - $arr1[-1]);
+
+ return $d1 > $d2 ? $d1 : $d2;
+}
+
+is(run([4, 5, 7], [9, 1, 3, 4]), 6, "Example 1");
+is(run([2, 3, 5, 4], [3, 2, 5, 5, 8, 7]), 6, "Example 2");
+is(run([2, 1, 11, 3], [2, 5, 10, 2]), 9, "Example 3");
+is(run([1, 2, 3], [3, 2, 1]), 2, "Example 4");
+is(run([1, 0, 2, 3], [5, 0]), 5, "Example 5");