diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-09-14 23:41:53 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-14 23:41:53 +0100 |
| commit | 3bc92b080e278e2376155fc87841420b972475e4 (patch) | |
| tree | 7f477e01b27f916c4285932a5fcf74bfd9a66bf3 | |
| parent | 75159e6eb9d43079bb3bfe1e067e5fb68cb67ddf (diff) | |
| parent | ce59cfe18826653836c121beeadb703b377fdd8d (diff) | |
| download | perlweeklychallenge-club-3bc92b080e278e2376155fc87841420b972475e4.tar.gz perlweeklychallenge-club-3bc92b080e278e2376155fc87841420b972475e4.tar.bz2 perlweeklychallenge-club-3bc92b080e278e2376155fc87841420b972475e4.zip | |
Merge pull request #12674 from BarrOff/barroff-338
feat: add solutions for challenge 338 from BarrOff
| -rw-r--r-- | challenge-338/barroff/raku/ch-1.p6 | 22 | ||||
| -rw-r--r-- | challenge-338/barroff/raku/ch-2.p6 | 22 |
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-338/barroff/raku/ch-1.p6 b/challenge-338/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..13614808a5 --- /dev/null +++ b/challenge-338/barroff/raku/ch-1.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env raku + +use v6.d; + +sub highest-row(@matrix --> Int) { + max(map({ sum($_) }, @matrix)) +} + +#| Run test cases +sub MAIN() { + use Test; + plan 5; + + is highest-row([[4, 4, 4, 4], + [10, 0, 0, 0], + [2, 2, 2, 9]]), 16, 'works for matrix one'; + is highest-row([[1, 5], [7, 3], [3, 5]]), 10, 'works for matrix two'; + is highest-row([[1, 2, 3], [3, 2, 1]]), 6, 'works for matrix three'; + is highest-row([[2, 8, 7], [7, 1, 3], [1, 9, 5]]), 17, 'works for matrix four'; + is highest-row([[10, 20, 30], [5, 5, 5], [0, 100, 0], [25, 25, 25]]), + 100, 'works for matrix five'; +} diff --git a/challenge-338/barroff/raku/ch-2.p6 b/challenge-338/barroff/raku/ch-2.p6 new file mode 100644 index 0000000000..839ef32a53 --- /dev/null +++ b/challenge-338/barroff/raku/ch-2.p6 @@ -0,0 +1,22 @@ +#!/usr/bin/env raku + +use v6.d; + +sub max-distance(@arr1, @arr2 --> Int) { + max(abs(max(@arr1) - min(@arr2)), abs(max(@arr2) - min(@arr1))) +} + +#| Run test cases +sub MAIN() { + use Test; + plan 5; + + is max-distance([4, 5, 7], [9, 1, 3, 4]), 6, + 'works for [4, 5, 7] and [9, 1, 3, 4]'; + is max-distance([2, 3, 5, 4], [3, 2, 5, 5, 8, 7]), 6, + 'works for [2, 3, 5, 4] and [3, 2, 5, 5, 8, 7]'; + is max-distance([2, 1, 11, 3], [2, 5, 10, 2]), 9, + 'works for [2, 1, 11, 3] and [2, 5, 10, 2]'; + is max-distance([1, 2, 3], [3, 2, 1]), 2, 'works for [1, 2, 3] and [3, 2, 1]'; + is max-distance([1, 0, 2, 3], [5, 0]), 5, 'works for [1, 0, 2, 3] and [5, 0]'; +} |
