diff options
| author | E. Choroba <choroba@matfyz.cz> | 2025-09-08 14:15:27 +0200 |
|---|---|---|
| committer | E. Choroba <choroba@matfyz.cz> | 2025-09-08 14:17:49 +0200 |
| commit | 11dd9990326da4ffa9d765d80148f8fe6e9cae65 (patch) | |
| tree | c4db2debdb48cca5e763f336adc8d30f7906e2a2 | |
| parent | cb150b4089bfaa27339dfd6bb4e51b580b12c32b (diff) | |
| download | perlweeklychallenge-club-11dd9990326da4ffa9d765d80148f8fe6e9cae65.tar.gz perlweeklychallenge-club-11dd9990326da4ffa9d765d80148f8fe6e9cae65.tar.bz2 perlweeklychallenge-club-11dd9990326da4ffa9d765d80148f8fe6e9cae65.zip | |
Add solutions to 338: Highest Row & Max Distance by E. Choroba
| -rwxr-xr-x | challenge-338/e-choroba/perl/ch-1.pl | 37 | ||||
| -rwxr-xr-x | challenge-338/e-choroba/perl/ch-2.pl | 18 |
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-338/e-choroba/perl/ch-1.pl b/challenge-338/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..7a8dac4534 --- /dev/null +++ b/challenge-338/e-choroba/perl/ch-1.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +use PDL; + +sub highest_row(@matrix) { + return pdl(@matrix)->sumover->max +} + +use Test::More tests => 5; + +is highest_row([4, 4, 4, 4], + [10, 0, 0, 0], + [2, 2, 2, 9]), + 16, 'Example 1'; + +is highest_row([1, 5], + [7, 3], + [3, 5]), + '10', 'Example 2'; + +is highest_row([1, 2, 3], + [3, 2, 1]), + 6, 'Example 3'; + +is highest_row([2, 8, 7], + [7, 1, 3], + [1, 9, 5]), + '17', 'Example 4'; + +is highest_row([10, 20, 30], + [5, 5, 5], + [0, 100, 0], + [25, 25, 25]), + 100, 'Example 5'; diff --git a/challenge-338/e-choroba/perl/ch-2.pl b/challenge-338/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..1a558fdaed --- /dev/null +++ b/challenge-338/e-choroba/perl/ch-2.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental qw( signatures ); + +use List::Util qw{ max min }; + +sub max_distance($arr1, $arr2) { + return max(max(@$arr1) - min(@$arr2), max(@$arr2) - min(@$arr1)) +} + +use Test::More tests => 5; + +is max_distance([4, 5, 7], [9, 1, 3, 4]), 6, 'Example 1'; +is max_distance([2, 3, 5, 4], [3, 2, 5, 5, 8, 7]), 6, 'Example 2'; +is max_distance([2, 1, 11, 3], [2, 5, 10, 2]), 9, 'Example 3'; +is max_distance([1, 2, 3], [3, 2, 1]), 2, 'Example 4'; +is max_distance([1, 0, 2, 3], [5, 0]), 5, 'Example 5'; |
