From de3f2c3af38332e71b443fc1260052f837213ff1 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 2 Jun 2025 10:01:28 -0600 Subject: Solve PWC324 --- challenge-324/wlmb/blog.txt | 1 + challenge-324/wlmb/perl/ch-1.pl | 17 +++++++++++++++++ challenge-324/wlmb/perl/ch-2.pl | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 challenge-324/wlmb/blog.txt create mode 100755 challenge-324/wlmb/perl/ch-1.pl create mode 100755 challenge-324/wlmb/perl/ch-2.pl 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); -- cgit