aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-217/wlmb/blog.txt2
-rwxr-xr-xchallenge-217/wlmb/perl/ch-1.pl27
-rwxr-xr-xchallenge-217/wlmb/perl/ch-2.pl14
3 files changed, 43 insertions, 0 deletions
diff --git a/challenge-217/wlmb/blog.txt b/challenge-217/wlmb/blog.txt
new file mode 100644
index 0000000000..79ddfd8646
--- /dev/null
+++ b/challenge-217/wlmb/blog.txt
@@ -0,0 +1,2 @@
+https://wlmb.github.io/2023/05/15/PWC217/
+
diff --git a/challenge-217/wlmb/perl/ch-1.pl b/challenge-217/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..c7e443f74d
--- /dev/null
+++ b/challenge-217/wlmb/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 217
+# Task 1: Sorted Matrix
+#
+# See https://wlmb.github.io/2023/05/15/PWC217/#task-1-sorted-matrix
+use v5.36;
+use PDL;
+use experimental "try";
+die <<~"FIN" unless @ARGV;
+ Usage: $0 '[[m11, m22, ...],[m21,m22,...],...]'
+ to find the third element of the sorted matrix elements mij.
+ FIN
+for(@ARGV){
+ try {
+ my $x=pdl($_); # Convert input string to pdl-ndarray
+ die "Expected a square matrix: $_"
+ unless $x->isa("PDL") and $x->dims==2 and $x->dim(0)==$x->dim(1);
+ my $result=$x
+ ->flat # convert to vector
+ ->qsort # sort its elements
+ ->at(2); # choose third smallest
+ say "$x->$result";
+ }
+ catch($e){
+ warn "$e";
+ }
+}
diff --git a/challenge-217/wlmb/perl/ch-2.pl b/challenge-217/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..c9c2013dfa
--- /dev/null
+++ b/challenge-217/wlmb/perl/ch-2.pl
@@ -0,0 +1,14 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 217
+# Task 2: Max Number
+#
+# See https://wlmb.github.io/2023/05/15/PWC217/#task-2-max-number
+use v5.36;
+use List::Util qw(all);
+die <<~"FIN" unless @ARGV;
+ Usage: $0 N1 [N2...]
+ to build the highest possible number by rearranging and concatenating
+ the numbers N1 N2...
+ FIN
+die "Expected nonnegative integers" unless all {/^\d+$/} @ARGV;
+say "@ARGV -> ", join "", sort {"$b$a" <=> "$a$b"} @ARGV;