aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-321/wlmb/blog.txt1
-rwxr-xr-xchallenge-321/wlmb/perl/ch-1.pl16
-rwxr-xr-xchallenge-321/wlmb/perl/ch-2.pl21
3 files changed, 38 insertions, 0 deletions
diff --git a/challenge-321/wlmb/blog.txt b/challenge-321/wlmb/blog.txt
new file mode 100644
index 0000000000..1e32450d96
--- /dev/null
+++ b/challenge-321/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2025/05/12/PWC321/
diff --git a/challenge-321/wlmb/perl/ch-1.pl b/challenge-321/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..ec97838dd8
--- /dev/null
+++ b/challenge-321/wlmb/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 321
+# Task 1: Distinct Average
+#
+# See https://wlmb.github.io/2025/05/12/PWC321/#task-1-distinct-average
+use v5.36;
+use List::Util qw(uniq);
+my $N=@ARGV;
+die <<~"FIN" unless $N && $N%2==0;
+ Usage: $0 N1 N2...N2n
+ to remove the smallest and largest value of the list, average them and
+ count the distinct values produced.
+ FIN
+my @sorted = sort {$a <=> $b} @ARGV;
+my $N2 = $N/2-1; #
+say "@ARGV -> ", scalar uniq map {$sorted[$_]+$sorted[-1-$_]} 0..$N2;
diff --git a/challenge-321/wlmb/perl/ch-2.pl b/challenge-321/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..a7ecb9ca5f
--- /dev/null
+++ b/challenge-321/wlmb/perl/ch-2.pl
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 321
+# Task 2: Backspace Compare
+#
+# See https://wlmb.github.io/2025/05/12/PWC321/#task-2-backspace-compare
+use v5.36;
+die <<~"FIN" unless @ARGV && @ARGV%2==0;
+ Usage: $0 A1 B1 A2 B2...
+ to find if strings An Bn are equal after all \#'s are
+ interpreted as backspace and applied to delete the preceding
+ character.
+ FIN
+for my($x, $y)(@ARGV){
+ my ($x_edited, $y_edited) = ($x, $y); # make a copy
+ ($x_edited, $y_edited) = map {
+ 1 while s/(^|[^\#])\#//g; # apply backspaces. Deal with # at beginning
+ $_; # return edited string
+ } ($x_edited, $y_edited);
+ my $result = $x_edited eq $y_edited? "True" : "False";
+ say "$x $y -> $result";
+}