aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2023-12-25 21:22:50 +0000
committerGitHub <noreply@github.com>2023-12-25 21:22:50 +0000
commit604839e3f6c93bc0004d5d6e2e31e1eaf9606d76 (patch)
tree229276955e70c82f05db6013598e64b1ad5e91ae
parent3669057e3de82bec9610e1c7d4d010135621bc50 (diff)
parent777ab736136f83ba3998097f725c6930f4d5164e (diff)
downloadperlweeklychallenge-club-604839e3f6c93bc0004d5d6e2e31e1eaf9606d76.tar.gz
perlweeklychallenge-club-604839e3f6c93bc0004d5d6e2e31e1eaf9606d76.tar.bz2
perlweeklychallenge-club-604839e3f6c93bc0004d5d6e2e31e1eaf9606d76.zip
Merge pull request #9291 from wlmb/challenges
Solve PWC249
-rw-r--r--challenge-249/wlmb/blog.txt1
-rwxr-xr-xchallenge-249/wlmb/perl/ch-1.pl16
-rwxr-xr-xchallenge-249/wlmb/perl/ch-2.pl18
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-249/wlmb/blog.txt b/challenge-249/wlmb/blog.txt
new file mode 100644
index 0000000000..1e7e09f85e
--- /dev/null
+++ b/challenge-249/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2023/12/25/PWC249/
diff --git a/challenge-249/wlmb/perl/ch-1.pl b/challenge-249/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..585a61df7d
--- /dev/null
+++ b/challenge-249/wlmb/perl/ch-1.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 249
+# Task 1: Equal Pairs
+#
+# See https://wlmb.github.io/2023/12/25/PWC249/#task-1-equal-pairs
+use v5.36;
+use List::Util qw(all);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 N1 [N2...]
+ to find pairs of equal numbers N_i == N_j
+ FIN
+my %count;
+$count{$_}++ for @ARGV;
+say "(@ARGV) => ",
+ (all {$_%2==0} values %count)
+ ? map {("($_ $_) ") x ($count{$_}/2)} sort {$a<=>$b} keys %count:"()"
diff --git a/challenge-249/wlmb/perl/ch-2.pl b/challenge-249/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..6c6ba12d05
--- /dev/null
+++ b/challenge-249/wlmb/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 249
+# Task 2: DI String Match
+#
+# See https://wlmb.github.io/2023/12/25/PWC249/#task-2-di-string-match
+use v5.36;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 S1 [S2...]
+ where S_i is a string of D's and I's, to produce a permutation of
+ indices 0..length of S_i that increases or decreases according to
+ the letters D or I.
+ FIN
+for(@ARGV){
+ my @output;
+ push @output,my $max=my $min=0;
+ push @output, ($_ eq "D")?++$max:--$min for reverse split "";
+ say "$_ => (",join(",", reverse map {$_-$min} @output), ")"
+}