aboutsummaryrefslogtreecommitdiff
path: root/challenge-218
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2023-05-22 21:19:11 +0000
committerMark <53903062+andemark@users.noreply.github.com>2023-05-22 21:19:11 +0000
commitc82b7c51dfb95d8f21ffd77e78e04d53e486a675 (patch)
tree8d194fb04f36b93687ecea077dc9a88aa0856e7b /challenge-218
parent02ef15bd7e68e35a558c767dacf1be6afb818581 (diff)
downloadperlweeklychallenge-club-c82b7c51dfb95d8f21ffd77e78e04d53e486a675.tar.gz
perlweeklychallenge-club-c82b7c51dfb95d8f21ffd77e78e04d53e486a675.tar.bz2
perlweeklychallenge-club-c82b7c51dfb95d8f21ffd77e78e04d53e486a675.zip
Challenge 218 Solutions (Raku)
Diffstat (limited to 'challenge-218')
-rw-r--r--challenge-218/mark-anderson/raku/ch-1.raku33
-rw-r--r--challenge-218/mark-anderson/raku/ch-2.raku90
2 files changed, 105 insertions, 18 deletions
diff --git a/challenge-218/mark-anderson/raku/ch-1.raku b/challenge-218/mark-anderson/raku/ch-1.raku
index 3c1936be9b..0ffa1553bb 100644
--- a/challenge-218/mark-anderson/raku/ch-1.raku
+++ b/challenge-218/mark-anderson/raku/ch-1.raku
@@ -1,21 +1,24 @@
#!/usr/bin/env raku
use Test;
-is max-product(3,1,2), 6;
-is max-product(4,1,3,2), 24;
-is max-product(-1,0,1,3,1), 3;
-is max-product(1,-2,3), -6;
-is max-product(4,0,-3,5), 0;
-is max-product(-3,-2,0,-4), 0;
-is max-product(-3,-2,1,-4), 12;
-is max-product(-3,-5,-2,-4), -24;
-is max-product(-1,-1,1,1), 1;
-is max-product(-1,-1,-1,0), 0;
-is max-product(-1,-1,-1,1), 1;
-is max-product(1,1,1,0), 1;
-is max-product(0,0,0,0), 0;
-is max-product(1,2,0,-1), 0;
-is max-product(-1,0,0,-1), 0;
+is max-product(3,1,2), 6;
+is max-product(4,1,3,2), 24;
+is max-product(-1,0,1,3,1), 3;
+is max-product(-8,2,-9,0,-4,3), 216;
+is max-product(-8,-9,0,0,0,1), 72;
+is max-product(1,-2,3,4,5), 60;
+is max-product(1,-2,3), -6;
+is max-product(4,0,-3,5), 0;
+is max-product(-3,-2,0,-4), 0;
+is max-product(-3,-2,1,-4), 12;
+is max-product(-3,-5,-2,-4), -24;
+is max-product(-1,-1,1,1), 1;
+is max-product(-1,-1,-1,0), 0;
+is max-product(-1,-1,-1,1), 1;
+is max-product(1,1,1,0), 1;
+is max-product(0,0,0,0), 0;
+is max-product(1,2,0,-1), 0;
+is max-product(-1,0,0,-1), 0;
multi max-product(+$a where .elems == 3)
{
diff --git a/challenge-218/mark-anderson/raku/ch-2.raku b/challenge-218/mark-anderson/raku/ch-2.raku
index 3a3248057e..0024345c85 100644
--- a/challenge-218/mark-anderson/raku/ch-2.raku
+++ b/challenge-218/mark-anderson/raku/ch-2.raku
@@ -3,9 +3,9 @@ use Test;
is matrix-score([0,0,1,1],
[1,0,1,0],
- [1,1,0,0]), 39;
+ [1,1,0,0]), 39;
-is matrix-score([0]), 1;
+is matrix-score([0]), 1;
is matrix-score([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
@@ -25,7 +25,91 @@ is matrix-score([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0],
[0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0],
[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0],
- [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]), 2246857;
+ [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]),
+ 2246857;
+
+is matrix-score([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
+ [1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
+ [1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1],
+ [1,1,1,0,0,0,0,0,0,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