aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-184/wlmb/blog.txt1
-rwxr-xr-xchallenge-184/wlmb/perl/ch-1.pl18
-rwxr-xr-xchallenge-184/wlmb/perl/ch-2.pl34
3 files changed, 53 insertions, 0 deletions
diff --git a/challenge-184/wlmb/blog.txt b/challenge-184/wlmb/blog.txt
new file mode 100644
index 0000000000..8124f68c5c
--- /dev/null
+++ b/challenge-184/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2022/09/26/PWC184/
diff --git a/challenge-184/wlmb/perl/ch-1.pl b/challenge-184/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..8060fe865c
--- /dev/null
+++ b/challenge-184/wlmb/perl/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 184
+# Task 1: Sequence Number
+#
+# See https://wlmb.github.io/2022/09/26/PWC184/#task-1-sequence-number
+use v5.36;
+die <<"EOF" unless @ARGV;
+Usage: $0 s1 [s2 ...]
+to replace the first 2 characters of strings S1 S2...
+by a two digit increasing code.
+The strings should be of the form lldddd where l is a letter a..z
+and d a digit 0..9.
+EOF
+die "More than 100 strings" if @ARGV>100;
+my $counter="00";
+say join ", ",
+ map {m/^[a-z]{2}\d{4}$/||die "Bad format $_\n"; s/../$counter++/e; $_}
+ @ARGV;
diff --git a/challenge-184/wlmb/perl/ch-2.pl b/challenge-184/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..66a16e8d35
--- /dev/null
+++ b/challenge-184/wlmb/perl/ch-2.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 184
+# Task 2: Split Array
+#
+# See https://wlmb.github.io/2022/09/26/PWC184/#task-2-split-array
+use v5.36;
+use experimental qw(for_list);
+use List::Util qw(reduce);
+
+sub arr2str(@X){ # recursively converts array to string
+ "[" . join(", ", map{ref $_ eq "ARRAY"? arr2str(@$_):$_} @X) . "]"
+}
+
+die <<EOF unless @ARGV;
+Usage: $0 S1 [S2...]
+to split strings S1, S2... into arrays of numbers and letters.
+Each string should contain space separated single letters a-z and/or digits 0-9.
+EOF
+for(@ARGV){ # check arguments
+ die "Wrong format: $_" unless /^[a-z0-9](\s+[a-z0-9])*$/;
+}
+
+my (@numbers_arr, @letters_arr); # arrays of array refs
+for my ($numbers,$letters)( # array refs
+ map { # separate each arg into number and letters array refs.
+ my(@numbers, @letters);
+ /^[0-9]$/ and push @numbers, $_ or push @letters, $_ for split " ";
+ [@numbers], [@letters]
+ } @ARGV
+) {
+ push @numbers_arr, $numbers if @$numbers; # ignore empty arrays
+ push @letters_arr, $letters if @$letters;
+}
+say arr2str(@numbers_arr), " and ", arr2str(@letters_arr);