aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Mochan <mochan@fis.unam.mx>2023-12-27 14:54:57 -0600
committerLuis Mochan <mochan@fis.unam.mx>2023-12-27 14:54:57 -0600
commit23f378718ed93b9b8d9e51fe18f07a55f61dc9c1 (patch)
tree36ad620541dd22184e95b711ce6966a064bc9489
parent777ab736136f83ba3998097f725c6930f4d5164e (diff)
downloadperlweeklychallenge-club-23f378718ed93b9b8d9e51fe18f07a55f61dc9c1.tar.gz
perlweeklychallenge-club-23f378718ed93b9b8d9e51fe18f07a55f61dc9c1.tar.bz2
perlweeklychallenge-club-23f378718ed93b9b8d9e51fe18f07a55f61dc9c1.zip
New solution to PWC248-2
-rwxr-xr-xchallenge-248/wlmb/perl/ch-2a.pl16
1 files changed, 16 insertions, 0 deletions
diff --git a/challenge-248/wlmb/perl/ch-2a.pl b/challenge-248/wlmb/perl/ch-2a.pl
new file mode 100755
index 0000000000..f0dfe67719
--- /dev/null
+++ b/challenge-248/wlmb/perl/ch-2a.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/env perl
+use v5.36;
+use PDL;
+use PDL::Image2D;
+die <<~"FIN" unless @ARGV==3;
+ Usage: $0 M W H
+ where M is a matrix "[[m11,m22...],[m21,m22....],...]"
+ and W and H are the size of a sliding window to make a matrix of HxW submatrices
+ and sum the submatrix matrix elements.
+ FIN
+my $m=pdl(shift);
+my $w=shift;
+my $h=shift;
+say "Input: $m Width $w, Height $h -> ",
+ $m->conv2d(ones($w,$h))->slice([floor(($w-1)/2),floor(-($w+1)/2)],
+ [floor(($h-1)/2),floor(-($h+1)/2)]);