diff options
| author | Luis Mochan <mochan@fis.unam.mx> | 2025-06-02 10:01:28 -0600 |
|---|---|---|
| committer | Luis Mochan <mochan@fis.unam.mx> | 2025-06-02 10:01:28 -0600 |
| commit | de3f2c3af38332e71b443fc1260052f837213ff1 (patch) | |
| tree | b3ab3b591c02ce45a9bdbaa94a3aacf70adcd3af | |
| parent | b0159e77cc4e56da3a5a1c86d5769c652bcc887e (diff) | |
| download | perlweeklychallenge-club-de3f2c3af38332e71b443fc1260052f837213ff1.tar.gz perlweeklychallenge-club-de3f2c3af38332e71b443fc1260052f837213ff1.tar.bz2 perlweeklychallenge-club-de3f2c3af38332e71b443fc1260052f837213ff1.zip | |
Solve PWC324
| -rw-r--r-- | challenge-324/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-324/wlmb/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-324/wlmb/perl/ch-2.pl | 16 |
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-324/wlmb/blog.txt b/challenge-324/wlmb/blog.txt new file mode 100644 index 0000000000..ad107aef57 --- /dev/null +++ b/challenge-324/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2025/06/02/PWC324/ diff --git a/challenge-324/wlmb/perl/ch-1.pl b/challenge-324/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..2438cc0333 --- /dev/null +++ b/challenge-324/wlmb/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Perl weekly challenge 324 +# Task 1: 2D Array +# +# See https://wlmb.github.io/2025/06/02/PWC324/#task-1-2d-array +use v5.36; +use PDL; +die <<~"FIN" unless @ARGV >= 3; + Usage: $0 R C D1 D2... + to reshape the array (D1 D2...) into a matrix with + R rows and C columns + FIN +my ($rows, $cols, @array)=@ARGV; +die "Number of elements should equal RxC" unless $rows*$cols==@array; +my $array=pdl(@array); +my $reshaped=$array->copy->reshape($cols, $rows); +say "rows=$rows, cols=$cols, array= $array -> $reshaped"; diff --git a/challenge-324/wlmb/perl/ch-2.pl b/challenge-324/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..af23ecc2e2 --- /dev/null +++ b/challenge-324/wlmb/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/env perl +# Perl weekly challenge 324 +# Task 2: Total XOR +# +# See https://wlmb.github.io/2025/06/02/PWC324/#task-2-total-xor +use v5.36; +use List::Util qw(reduce sum); +sub f(@x){ + if(@x){ + my ($first, @rest)=@x; + my @reduced=f(@rest); + return @reduced, map{$first^$_}@reduced; + } + return (0); +} +say "@ARGV -> ", sum f(@ARGV); |
