aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-256/wlmb/perl/ch-1.pl2
-rwxr-xr-xchallenge-256/wlmb/perl/ch-1a.pl19
2 files changed, 20 insertions, 1 deletions
diff --git a/challenge-256/wlmb/perl/ch-1.pl b/challenge-256/wlmb/perl/ch-1.pl
index 4163c91776..f5da52e2e6 100755
--- a/challenge-256/wlmb/perl/ch-1.pl
+++ b/challenge-256/wlmb/perl/ch-1.pl
@@ -7,7 +7,7 @@ use v5.36;
use List::Util qw(sum0);
die <<~"FIN" unless @ARGV;
Usage: $0 S1 [S2...]
- to pair Si with the reverse SJ and count the resulting pairs
+ to pair Si with the reverse Sj and count the resulting pairs
assuming at most one pair per string.
FIN
my %count;
diff --git a/challenge-256/wlmb/perl/ch-1a.pl b/challenge-256/wlmb/perl/ch-1a.pl
new file mode 100755
index 0000000000..8da7ff0e39
--- /dev/null
+++ b/challenge-256/wlmb/perl/ch-1a.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 256
+# Task 1: Maximum Pairs
+#
+# See https://wlmb.github.io/2024/02/12/PWC256/#task-1-maximum-pairs
+use v5.36;
+use List::Util qw(sum0);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 S1 [S2...]
+ to pair Si with the reverse Sj and count the resulting pairs
+ FIN
+my %count;
+++$count{$_} for (@ARGV);
+my $result = (sum0 map {
+ my $reverse=reverse $_;
+ my $selfreverse=$_ eq $reverse;
+ $count{$_}*(($count{$reverse}//0)-$selfreverse)
+} keys %count)/2;
+say "@ARGV -> $result";