aboutsummaryrefslogtreecommitdiff
path: root/challenge-248
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-12-21 01:05:30 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-12-21 01:05:30 +0000
commita04ded57f1d184eefeb0f192502338b46064b8e9 (patch)
treeb561f961df6f3b3d2f82fa9e85a1cd7df6762d06 /challenge-248
parent33f4358de5040ddc31b53689b6a781efbc2847c1 (diff)
downloadperlweeklychallenge-club-a04ded57f1d184eefeb0f192502338b46064b8e9.tar.gz
perlweeklychallenge-club-a04ded57f1d184eefeb0f192502338b46064b8e9.tar.bz2
perlweeklychallenge-club-a04ded57f1d184eefeb0f192502338b46064b8e9.zip
- Added solutions by Matthew Neleigh.
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-248')
-rw-r--r--challenge-248/laurent-rosenfeld/blog1.txt1
-rw-r--r--challenge-248/laurent-rosenfeld/raku/ch-2.raku30
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-248/laurent-rosenfeld/blog1.txt b/challenge-248/laurent-rosenfeld/blog1.txt
new file mode 100644
index 0000000000..252bb3dec4
--- /dev/null
+++ b/challenge-248/laurent-rosenfeld/blog1.txt
@@ -0,0 +1 @@
+https://blogs.perl.org/users/laurent_r/2023/12/perl-weekly-challenge-248-submatrix-sum.html
diff --git a/challenge-248/laurent-rosenfeld/raku/ch-2.raku b/challenge-248/laurent-rosenfeld/raku/ch-2.raku
new file mode 100644
index 0000000000..56c99eac9b
--- /dev/null
+++ b/challenge-248/laurent-rosenfeld/raku/ch-2.raku
@@ -0,0 +1,30 @@
+sub submatrix-sum (@in) {
+ my $max-row = @in.end;
+ my $max-col = @in[0].end;
+ my @result;
+ for 0..^$max-row -> $i {
+ my @row;
+ for 0..^$max-col -> $j {
+ push @row, @in[$i][$j] + @in[$i][$j+1] +
+ @in[$i+1][$j] + @in[$i+1][$j+1];
+ }
+ push @result, @row; # push doesn't flatten
+ }
+ return @result;
+}
+
+my @tests = [
+ [1, 2, 3, 4],
+ [5, 6, 7, 8],
+ [9, 10, 11, 12]
+ ],
+ [
+ [1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, 0],
+ [0, 0, 0, 1]
+ ];
+for @tests -> @test {
+ print @test.gist, " => ";;
+ say submatrix-sum @test;
+}