aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-211/mark-anderson/raku/ch-1.raku25
-rw-r--r--challenge-211/mark-anderson/raku/ch-2.raku22
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-211/mark-anderson/raku/ch-1.raku b/challenge-211/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..4519f643b6
--- /dev/null
+++ b/challenge-211/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,25 @@
+#!/usr/bin/env raku
+use Test;
+
+ok toeplitz([4, 3, 2, 1],
+ [5, 4, 3, 2],
+ [6, 5, 4, 3]);
+
+nok toeplitz([1, 2, 3],
+ [3, 2, 1]);
+
+ok toeplitz([4, 3, 2, 1],
+ [5, 4, 3, 2],
+ [6, 5, 4, 3],
+ [7, 6, 5, 4],
+ [8, 7, 6, 5]);
+
+ok toeplitz([1,2],
+ [2,1],
+ [3,2],
+ [4,3]);
+
+sub toeplitz(+@m)
+{
+ @m[ ^@m.end; ^@m[0].end ] eqv @m[ 1..@m.end; 1..@m[1].end ]
+}
diff --git a/challenge-211/mark-anderson/raku/ch-2.raku b/challenge-211/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..255ada41f4
--- /dev/null
+++ b/challenge-211/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+use Test;
+
+ok split-same-avg(1,2,3,4,5,6,7,8); # [1 8] [2 3 4 5 6 7]
+nok split-same-avg(1,3);
+ok split-same-avg(3,3,5,5,5,2,2,1); # [2 3 3 5] [1 2 5 5]
+nok split-same-avg(5,5,5,2,2,1);
+
+sub split-same-avg(*@nums)
+{
+ for (^@nums).combinations(1..@nums.elems div 2) -> @a is copy
+ {
+ my @b = (^@nums (-) @a).keys;
+
+ @a = @nums[@a];
+ @b = @nums[@b];
+
+ return True if @a.sum / @a.elems == @b.sum / @b.elems
+ }
+
+ return False
+}