diff options
| author | Scimon <simon.proctor@gmail.com> | 2025-09-09 10:01:44 +0100 |
|---|---|---|
| committer | Scimon <simon.proctor@gmail.com> | 2025-09-09 10:01:44 +0100 |
| commit | 829110e9ee2d13e211a310ee92f5999df491e205 (patch) | |
| tree | 7c42aa96658d0e22584fdb2a5ef83e359d692e99 | |
| parent | 1d073851f64d0b9edfb3966c3bf788528e72bbf4 (diff) | |
| download | perlweeklychallenge-club-829110e9ee2d13e211a310ee92f5999df491e205.tar.gz perlweeklychallenge-club-829110e9ee2d13e211a310ee92f5999df491e205.tar.bz2 perlweeklychallenge-club-829110e9ee2d13e211a310ee92f5999df491e205.zip | |
Challenge 338
| -rwxr-xr-x | challenge-338/simon-proctor/raku/ch-1.raku | 32 | ||||
| -rwxr-xr-x | challenge-338/simon-proctor/raku/ch-2.raku | 22 |
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; +} |
