aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-01 13:12:34 +0100
committerGitHub <noreply@github.com>2025-09-01 13:12:34 +0100
commit5495d56b217e6dc102eaf5c839c1f6903785d052 (patch)
tree8fded62f66080968761a26ef17764f74fb6754ec
parente80c93c27044ee16a834a9ee64a0087c1c7d0b1d (diff)
parenta1ac4b336cebee58390b4992de700ee987924a72 (diff)
downloadperlweeklychallenge-club-5495d56b217e6dc102eaf5c839c1f6903785d052.tar.gz
perlweeklychallenge-club-5495d56b217e6dc102eaf5c839c1f6903785d052.tar.bz2
perlweeklychallenge-club-5495d56b217e6dc102eaf5c839c1f6903785d052.zip
Merge pull request #12604 from wlmb/challenges
Solve PWC337
-rw-r--r--challenge-337/wlmb/blog.txt1
-rwxr-xr-xchallenge-337/wlmb/perl/ch-1.pl19
-rwxr-xr-xchallenge-337/wlmb/perl/ch-2.pl24
3 files changed, 44 insertions, 0 deletions
diff --git a/challenge-337/wlmb/blog.txt b/challenge-337/wlmb/blog.txt
new file mode 100644
index 0000000000..c5629a9829
--- /dev/null
+++ b/challenge-337/wlmb/blog.txt
@@ -0,0 +1 @@
+https://wlmb.github.io/2025/08/31/PWC337/
diff --git a/challenge-337/wlmb/perl/ch-1.pl b/challenge-337/wlmb/perl/ch-1.pl
new file mode 100755
index 0000000000..d55e88b622
--- /dev/null
+++ b/challenge-337/wlmb/perl/ch-1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 337
+# Task 1: Smaller Than Current
+#
+# See https://wlmb.github.io/2025/08/31/PWC337/#task-1-smaller-than-current
+use v5.36;
+use PDL;
+use PDL::NiceSlice;
+die <<~"FIN" unless @ARGV;
+ Usage: $0 A1 A2...
+ to find for each number Ni in the array Ak how many numbers Nj
+ are less than Ni.
+ The arrays are input as strings of the form
+ "[N0 N1 ...]" where the Ni's are numbers
+ FIN
+for(@ARGV){
+ my $array=pdl($_);
+ say "$_ -> ",($array(*1)>$array)->sumover; # compare array as cols vs. as rows
+}
diff --git a/challenge-337/wlmb/perl/ch-2.pl b/challenge-337/wlmb/perl/ch-2.pl
new file mode 100755
index 0000000000..59030549b4
--- /dev/null
+++ b/challenge-337/wlmb/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+# Perl weekly challenge 337
+# Task 2: Odd Matrix
+#
+# See https://wlmb.github.io/2025/08/31/PWC337/#task-2-odd-matrix
+use v5.36;
+use PDL;
+use PDL::NiceSlice;
+use feature qw(try);
+die <<~"FIN" unless @ARGV and @ARGV%3==0;
+ Usage: $0 R1 C1 P1 R2 C2 P2...
+ to find how many odd numbers are in a matrix of Ri rows and Ci columns
+ after the rows and columns corresponding to the points Pi are incremented,
+ where Pi is input as a string with the format "[[r1 c1][r2 c2]...]"
+ FIN
+for my($rows,$cols,$points)(@ARGV){
+ try {
+ my $matrix=zeroes($cols,$rows);
+ my $locations=pdl($points);
+ $matrix(($_))++ for $locations->slice("(1)")->dog; # increment columns
+ $matrix(,($_))++ for $locations->slice("(0)")->dog; # increment rows
+ say "Rows=$rows, Cols=$cols, Locations=$points -> ", ($matrix%2)->sum
+ } catch($e) { say $e;}
+}