diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-09-08 09:06:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-08 09:06:56 +0100 |
| commit | e0d34d876e3e20819b2270ec9534fa264610f4ab (patch) | |
| tree | 77185c7f45bebbd49a422ea4b6f5bc7b02715b57 | |
| parent | 709efb104ac6cc51bcc6c6b6cec73b379807216a (diff) | |
| parent | f710722f0c0725575f5f77d048c3815090e70f38 (diff) | |
| download | perlweeklychallenge-club-e0d34d876e3e20819b2270ec9534fa264610f4ab.tar.gz perlweeklychallenge-club-e0d34d876e3e20819b2270ec9534fa264610f4ab.tar.bz2 perlweeklychallenge-club-e0d34d876e3e20819b2270ec9534fa264610f4ab.zip | |
Merge pull request #12638 from wlmb/challenges
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..145bcade82 --- /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){warn $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..248fa4a59b --- /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){ warn $e } +} |
