aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-02-13 10:34:44 +0000
committerGitHub <noreply@github.com>2024-02-13 10:34:44 +0000
commit53eff8111b449be370f5468c2d6c992b549cbc6c (patch)
tree1d0040cabb39a300086e6e41b35dfef9e0013419
parent3b9a221b247412bea4c3b9ede7b74c1de8c07124 (diff)
parent5eb1424cfc9adf481ad4b79640a060abffd65d1c (diff)
downloadperlweeklychallenge-club-53eff8111b449be370f5468c2d6c992b549cbc6c.tar.gz
perlweeklychallenge-club-53eff8111b449be370f5468c2d6c992b549cbc6c.tar.bz2
perlweeklychallenge-club-53eff8111b449be370f5468c2d6c992b549cbc6c.zip
Merge pull request #9579 from wlmb/challenges
Solve PWC256
-rw-r--r--challenge-256/wlmb/blog.txt1
-rwxr-xr-xchallenge-256/wlmb/perl/ch-1.pl20
-rwxr-xr-xchallenge-256/wlmb/perl/ch-2.pl13
3 files changed, 34 insertions, 0 deletions
diff --git a/challenge-256/wlmb/blog.txt b/challenge-256/wlmb/blog.txt
new file mode 100644
index 0000000000..618be058ba
--- /dev/null
+++ b/challenge-256/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2024/02/12/PWC256/
diff --git a/challenge-256/wlmb/perl/ch-1.pl b/challenge-256/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..4163c91776
--- /dev/null
+++ b/challenge-256/wlmb/perl/ch-1.pl
@@ -0,0 +1,20 @@
+#!/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
+ assuming at most one pair per string.
+ FIN
+my %count;
+my $reverse;
+for (@ARGV){
+ ++$count{$_};
+ my $reverse=reverse $_;
+ --$count{$reverse} unless $reverse eq $_;
+}
+say "@ARGV -> ", (sum0 map {!$_} values %count)/2;
diff --git a/challenge-256/wlmb/perl/ch-2.pl b/challenge-256/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..3a1cccab74
--- /dev/null
+++ b/challenge-256/wlmb/perl/ch-2.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 256
+# Task 2: Merge Strings
+#
+# See https://wlmb.github.io/2024/02/12/PWC256/#task-2-merge-strings
+use v5.36;
+sub next_char($x){
+ shift @$x||""
+}
+my ($x,$y)=map{[split ""]}@ARGV;
+my $out="";
+$out.=next_char($x) . next_char($y) while(@$x||@$y);
+say "@ARGV -> $out"