aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-22 18:21:40 +0000
committerGitHub <noreply@github.com>2024-01-22 18:21:40 +0000
commite5950fec13757372c56fd4a6fe34acb64e03f261 (patch)
tree6b712973a4e6fcfbee2d7cf5be66e67767b1c4d8
parent298fcd526074f0ea35c7bbe226b545c66038cab9 (diff)
parent7524d182663bb50444f547955649e6d9698807c6 (diff)
downloadperlweeklychallenge-club-e5950fec13757372c56fd4a6fe34acb64e03f261.tar.gz
perlweeklychallenge-club-e5950fec13757372c56fd4a6fe34acb64e03f261.tar.bz2
perlweeklychallenge-club-e5950fec13757372c56fd4a6fe34acb64e03f261.zip
Merge pull request #9446 from wlmb/challenges
Solve PWC253
-rw-r--r--challenge-253/wlmb/blog.txt1
-rwxr-xr-xchallenge-253/wlmb/perl/ch-1.pl15
-rwxr-xr-xchallenge-253/wlmb/perl/ch-2.pl25
3 files changed, 41 insertions, 0 deletions
diff --git a/challenge-253/wlmb/blog.txt b/challenge-253/wlmb/blog.txt
new file mode 100644
index 0000000000..1d1f21bcd0
--- /dev/null
+++ b/challenge-253/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2024/01/22/PWC253/
diff --git a/challenge-253/wlmb/perl/ch-1.pl b/challenge-253/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..92cc830d46
--- /dev/null
+++ b/challenge-253/wlmb/perl/ch-1.pl
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 253
+# Task 1: Split Strings
+#
+# See https://wlmb.github.io/2024/01/22/PWC253/#task-1-split-strings
+use v5.36;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 S W1 [W2...]
+ to separate words W1 W2... at separator character S.
+ FIN
+my $separator = shift;
+die "Only single characterr allowed as separator: $separator" unless $separator=~/^.$/;
+my @results;
+push @results, grep {/./} split /[$separator]/ for (@ARGV);
+say "Separator: $separator, input: @ARGV => output: @results";
diff --git a/challenge-253/wlmb/perl/ch-2.pl b/challenge-253/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..4b0e1cfadc
--- /dev/null
+++ b/challenge-253/wlmb/perl/ch-2.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 253
+# Task 2: Weakest Row
+#
+# See https://wlmb.github.io/2024/01/22/PWC253/#task-2-weakest-row
+use v5.36;
+use List::Util qw(all sum0);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 R0 [R1...]
+ to order the indices of the rows R_i of a binary matrix
+ from weakest to strongest, where R_i is represented as
+ a binary string.
+ FIN
+die "Only binary strings allowed" unless all {m/^[01]+$/} @ARGV;
+my @matrix;
+push @matrix, [split ""] for(@ARGV);
+say format_matrix(@matrix), "\n-> ",
+ join " ",
+ map {$_->[0]}
+ sort {$a->[1] <=> $b->[1] || $a->[0] <=> $b->[0]}
+ map {[$_, sum0 $matrix[$_]->@*]}
+ 0..@matrix-1;
+sub format_matrix(@m){
+ return "[\n", (map {" [ @$_ ]\n"} @m), "]"
+}