diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-03 13:10:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-03 13:10:46 +0100 |
| commit | 57b4080ab1c59477d8b8951525f07c07d572731e (patch) | |
| tree | 5d5827795794854b8bbcb89f558eec85f505855f | |
| parent | 571e86df9182af9f90391d6c87b76b7ff7153381 (diff) | |
| parent | de3f2c3af38332e71b443fc1260052f837213ff1 (diff) | |
| download | perlweeklychallenge-club-57b4080ab1c59477d8b8951525f07c07d572731e.tar.gz perlweeklychallenge-club-57b4080ab1c59477d8b8951525f07c07d572731e.tar.bz2 perlweeklychallenge-club-57b4080ab1c59477d8b8951525f07c07d572731e.zip | |
Merge pull request #12124 from wlmb/challenges
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); |
