aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Anderson <mark@andemark.io>2025-09-01 07:03:46 +0000
committerMark Anderson <mark@andemark.io>2025-09-01 07:03:46 +0000
commit7d4ec5d79e28470c2a1771d4496110dcd100139c (patch)
tree3ecd1d4c480aaad194ffb634e599a0ddbe64fed3
parente80c93c27044ee16a834a9ee64a0087c1c7d0b1d (diff)
downloadperlweeklychallenge-club-7d4ec5d79e28470c2a1771d4496110dcd100139c.tar.gz
perlweeklychallenge-club-7d4ec5d79e28470c2a1771d4496110dcd100139c.tar.bz2
perlweeklychallenge-club-7d4ec5d79e28470c2a1771d4496110dcd100139c.zip
Challenge 337 Solutions (Raku)
-rw-r--r--challenge-337/mark-anderson/raku/ch-1.raku16
-rw-r--r--challenge-337/mark-anderson/raku/ch-2.raku16
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-337/mark-anderson/raku/ch-1.raku b/challenge-337/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..c10832763b
--- /dev/null
+++ b/challenge-337/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply stc(6,5,4,8), (2,1,0,3);
+is-deeply stc(7,7,7,7), (0,0,0,0);
+is-deeply stc(5,4,3,2,1), (4,3,2,1,0);
+is-deeply stc(-1,0,3,-2,1), (1,2,4,0,3);
+is-deeply stc(0,1,1,2,0), (0,2,2,4,0);
+
+sub stc(+@nums)
+{
+ my %bag is Bag = @nums.Bag;
+ my @keys = %bag.keys.sort;
+ my %map is Map = @keys Z=> [\+] 0, |%bag{@keys};
+ %map{@nums}
+}
diff --git a/challenge-337/mark-anderson/raku/ch-2.raku b/challenge-337/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..f67ef8893f
--- /dev/null
+++ b/challenge-337/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/env raku
+use Test;
+
+is odd-matrix(2,3,[[0,1],[1,1]]), 6;
+is odd-matrix(2,2,[[1,1],[0,0]]), 0;
+is odd-matrix(3,3,[[0,0],[1,2],[2,1]]), 0;
+is odd-matrix(1,5,[[0,2],[0,4]]), 2;
+is odd-matrix(4,2,[[1,0],[3,1],[2,0],[0,1]]), 8;
+
+sub odd-matrix($rows, $cols, @locations)
+{
+ my @m = (0 xx $cols).Array xx $rows;
+ @m[@locations>>[0];*]>>++;
+ @m[*;@locations>>[1]]>>++;
+ @m[*;*].grep(*.ends-with(any 1,3,5,7,9)).elems
+}