diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2025-09-07 19:49:53 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2025-09-07 19:49:53 -0600 |
| commit | 7fc9d00bc648a3047b554bd4a3f5d571333bc771 (patch) | |
| tree | 197461ad485339198368272870c8b748c01ce3f9 | |
| parent | 12d9b7370121f12b601562856772ed3c03f7bb94 (diff) | |
| download | perlweeklychallenge-club-7fc9d00bc648a3047b554bd4a3f5d571333bc771.tar.gz perlweeklychallenge-club-7fc9d00bc648a3047b554bd4a3f5d571333bc771.tar.bz2 perlweeklychallenge-club-7fc9d00bc648a3047b554bd4a3f5d571333bc771.zip | |
Solve PWC338
| -rw-r--r-- | challenge-338/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-338/wlmb/perl/ch-1.pl | 19 | ||||
| -rwxr-xr-x | challenge-338/wlmb/perl/ch-2.pl | 25 |
3 files changed, 45 insertions, 0 deletions
diff --git a/challenge-338/wlmb/blog.txt b/challenge-338/wlmb/blog.txt new file mode 100644 index 0000000000..64398a8fac --- /dev/null +++ b/challenge-338/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/09/07/PWC338/ diff --git a/challenge-338/wlmb/perl/ch-1.pl b/challenge-338/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..d5eb7efa6e --- /dev/null +++ b/challenge-338/wlmb/perl/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +# Perl weekly challenge 338 +# Task 1: Highest Row +# +# See https://wlmb.github.io/2025/09/07/PWC338/#task-1-highest-row +use v5.36; +use feature qw(try); +use PDL; +die <<~"FIN" unless @ARGV; + Usage: $0 M1 M2... + to find the maximum rowwise sum of the elements of the + matrices Mi. The inputs are strings of the form + "[[m00 m01...][m10 m11...]...]" which may be parsed + by pdl as a matrix + FIN +for(@ARGV){ + try{say "$_ -> ", pdl($_)->sumover->max} + catch($e){say $e} +} diff --git a/challenge-338/wlmb/perl/ch-2.pl b/challenge-338/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..f77b352676 --- /dev/null +++ b/challenge-338/wlmb/perl/ch-2.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +# Perl weekly challenge 338 +# Task 2: Max Distance +# +# See https://wlmb.github.io/2025/09/07/PWC338/#task-2-max-distance +use v5.36; +use feature qw(try); +use PDL; +use PDL::NiceSlice; +die <<~"FIN" unless @ARGV and @ARGV%2==0; + Usage: $0 X1 Y1 X2 Y2... + to find the maximum distance between the elements of array Xi and Yi. + The inputs Xi and Yi are strings that may be parsed by ~PDL~ as arrays + of the form "[z0 z1...]" + FIN +for my ($x, $y)(@ARGV){ + try { + # initialize $p and $q with the min and max of each input + my ($p, $q)=map {pdl(pdl($_)->minmax)} ($x,$y); + # reverse one array to subtract minimum from maximum and maximum from minimum + my $result = ($p-$q(-1:0))->abs->max; + say "$x, $y -> ", $result; + } + catch($e){ say $e } +} |
