diff options
| -rw-r--r-- | challenge-249/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-249/wlmb/perl/ch-1.pl | 16 | ||||
| -rwxr-xr-x | challenge-249/wlmb/perl/ch-2.pl | 18 |
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), ")" +} |
