aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-09 10:07:59 +0100
committerGitHub <noreply@github.com>2025-09-09 10:07:59 +0100
commit91d6138a8fbda0d8e956f57eaf2a8f046ee4187a (patch)
tree79b3160f9ed1eac15816d5e231a159edaf89c99c
parentee0a6a958eeeb4e97c2f7accaeebfc6d315c2f15 (diff)
parent829110e9ee2d13e211a310ee92f5999df491e205 (diff)
downloadperlweeklychallenge-club-91d6138a8fbda0d8e956f57eaf2a8f046ee4187a.tar.gz
perlweeklychallenge-club-91d6138a8fbda0d8e956f57eaf2a8f046ee4187a.tar.bz2
perlweeklychallenge-club-91d6138a8fbda0d8e956f57eaf2a8f046ee4187a.zip
Merge pull request #12654 from Scimon/master
Challenge 338
-rwxr-xr-xchallenge-338/simon-proctor/raku/ch-1.raku32
-rwxr-xr-xchallenge-338/simon-proctor/raku/ch-2.raku22
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-338/simon-proctor/raku/ch-1.raku b/challenge-338/simon-proctor/raku/ch-1.raku
new file mode 100755
index 0000000000..c32c5cb1ee
--- /dev/null
+++ b/challenge-338/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,32 @@
+#!/usr/bin/env raku
+
+multi sub MAIN(:t(:$test)) is hidden-from-USAGE {
+ use Test;
+ is highest-row( [[4, 4, 4, 4],
+ [10, 0, 0, 0],
+ [2, 2, 2, 9]] ), 16;
+ is highest-row( [[1, 5],
+ [7, 3],
+ [3, 5]]), 10;
+ is highest-row( [[1, 2, 3],
+ [3, 2, 1]]), 6;
+ is highest-row( [[2, 8, 7],
+ [7, 1, 3],
+ [1, 9, 5]] ),17;
+ is highest-row( [[10, 20, 30],
+ [5, 5, 5],
+ [0, 100, 0],
+ [25, 25, 25]] ), 100;
+ done-testing;
+}
+
+#| Given a list of comma seperated matrix rows print the highest sum of row values
+multi sub MAIN(
+ *@rows #= Comma seperate list of matrix rows
+) {
+ highest-row( @rows.map(*.comb(/'-'?\d/)) ).say;
+}
+
+sub highest-row( @matrix ) {
+ @matrix.map( -> @row { [+] @row } ).max;
+}
diff --git a/challenge-338/simon-proctor/raku/ch-2.raku b/challenge-338/simon-proctor/raku/ch-2.raku
new file mode 100755
index 0000000000..a34082f068
--- /dev/null
+++ b/challenge-338/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+
+multi sub MAIN(:t(:$test)) is hidden-from-USAGE {
+ use Test;
+ is max-distance( (4, 5, 7), (9, 1, 3, 4) ), 6;
+ is max-distance((2, 3, 5, 4), (3, 2, 5, 5, 8, 7) ), 6;
+ is max-distance( (2, 1, 11, 3), (2, 5, 10, 2) ), 9;
+ is max-distance( (1, 2, 3), (3, 2, 1) ), 2;
+ is max-distance( (1, 0, 2, 3), (5, 0) ), 5;
+ done-testing;
+}
+
+sub max-distance( @a, @b ) {
+ (@a X- @b)>>.abs.max;
+}
+
+#| Given two comma seperated lists print the max distance between values
+multi sub MAIN( $a #= Comma seperated list of numbers
+ , $b #= Comma seperated lists of numbers
+ ) {
+ max-distance( $a.split(','), $b.split(',') ).say;
+}