aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrir <rirans@comcast.net>2025-09-12 13:07:15 -0400
committerrir <rirans@comcast.net>2025-09-16 10:03:29 -0400
commit716d4a307f784681047a0dd1caae2a4fda01013f (patch)
tree35e67827f0f4514a85d2856cd863dfbfe2989fea
parent65fdce07ae9b197000d4c64b9f1699cef16befe8 (diff)
downloadperlweeklychallenge-club-716d4a307f784681047a0dd1caae2a4fda01013f.tar.gz
perlweeklychallenge-club-716d4a307f784681047a0dd1caae2a4fda01013f.tar.bz2
perlweeklychallenge-club-716d4a307f784681047a0dd1caae2a4fda01013f.zip
338
-rw-r--r--challenge-338/0rir/raku/ch-1.raku81
-rw-r--r--challenge-338/0rir/raku/ch-2.raku67
2 files changed, 148 insertions, 0 deletions
diff --git a/challenge-338/0rir/raku/ch-1.raku b/challenge-338/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..4a5c385c8b
--- /dev/null
+++ b/challenge-338/0rir/raku/ch-1.raku
@@ -0,0 +1,81 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ 🐧
+use v6.e.PREVIEW;
+use Test;
+
+=begin comment
+Edited for space.
+338-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.
+
+Example 1
+Input: @matrix = ([4, 4, 4, 4],
+ [10, 0, 0, 0],
+ [2, 2, 2, 9])
+Output: 16
+
+Row 1: 4 + 4 + 4 + 4 => 16
+Row 2: 10 + 0 + 0 + 0 => 10
+Row 3: 2 + 2 + 2 + 9 => 15
+
+Example 2
+Input: @matrix = ([1, 5],
+ [7, 3],
+ [3, 5])
+Output: 10
+
+Example 3
+Input: @matrix = ([1, 2, 3],
+ [3, 2, 1])
+Output: 6
+
+Example 4
+Input: @matrix = ([2, 8, 7],
+ [7, 1, 3],
+ [1, 9, 5])
+Output: 17
+
+Example 5
+Input: @matrix = ([10, 20, 30],
+ [5, 5, 5],
+ [0, 100, 0],
+ [25, 25, 25])
+Output: 100
+=end comment
+
+=begin comment
+How are empty rows and undefined elements to be valued? Here they are ignored.
+Empty input dies.
+=end comment
+
+my @Test =
+ [[4, 4, 4, 4], [10, 0, 0, 0], [2, 2, 2, 9]], 16,
+ [[1, 5], [7, 3], [3, 5]], 10,
+ [[1, 2, 3], [3, 2, 1]], 6,
+ [[2, 8, 7], [7, 1, 3], [1, 9, 5]], 17,
+ [[10, 20, 30], [5, 5, 5], [0, 100, 0], [25, 25, 25]], 100,
+ [[ 2,], []], 2,
+ [[ -2,], []], -2,
+ [[ -2,], [Int,]], -2,
+ [[ -2,], [Int, 0]], 0,
+;
+
+plan 1 + +@Test ÷ 2;
+
+multi task( Empty ) { die 'Empty input.' }
+
+multi task( @a is copy --> Int) {
+ for @a -> @r { @r.=grep( { $_.defined } ); }
+ @a.=grep( ? * ) ;
+ max @a».sum;
+}
+
+dies-ok { task( []) }, "Die <- []";
+
+for @Test -> @in, $exp {
+ is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()";
+}
+
+done-testing;
diff --git a/challenge-338/0rir/raku/ch-2.raku b/challenge-338/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..e4f563eb64
--- /dev/null
+++ b/challenge-338/0rir/raku/ch-2.raku
@@ -0,0 +1,67 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ 🐧
+use v6.e.PREVIEW;
+use Test;
+
+=begin comment
+
+Edited for space.
+338- 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.
+
+Example 1
+Input: @arr1 = (4, 5, 7)
+ @arr2 = (9, 1, 3, 4)
+Output: 6
+
+With element $arr1[0] = 4
+| 4 - 9 | = 5
+| 4 - 1 | = 3
+| 4 - 3 | = 1
+| 4 - 4 | = 0
+max distance = 5
+
+With element $arr1[1] = 5
+| 5 - 9 | = 4
+| 5 - 1 | = 4
+| 5 - 3 | = 2
+| 5 - 4 | = 1
+max distance = 4
+
+With element $arr1[2] = 7
+| 7 - 9 | = 2
+| 7 - 1 | = 6
+| 7 - 3 | = 4
+| 7 - 4 | = 4
+max distance = 6
+
+max (5, 6, 6) = 6
+
+=end comment
+
+my @Test =
+ (4, 5, 7), (9, 1, 3, 4), 6,
+ (2, 3, 5, 4), (3, 2, 5, 5, 8, 7), 6,
+ (2, 1, 11, 3), (2, 5, 10, 2), 9,
+ (1, 2, 3), (3, 2, 1), 2,
+ (1, 0, 2, 3), (5, 0), 5,
+;
+
+plan +@Test ÷ 3;
+
+sub task( @a, @b -->Int) {
+ max max(@a) - min( @b), max(@b) - min( @a);
+}
+
+for @Test -> @i, @n, $exp {
+ is task( @i, @n), $exp, "{$exp // $exp.^name()} <- @i.raku(), @n.raku()";
+}
+done-testing;
+
+my @arr1 = 1, 0, 2, 3;
+my @arr2 = 5, 0;
+say "\nInput: @arr1 = (@arr1.raku())\n @arr2 = (@arr2.raku())\n"
+ ~ "Output: ", task( @arr1, @arr2);
+