aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-343/mark-anderson/raku/ch-1.raku33
-rw-r--r--challenge-343/mark-anderson/raku/ch-2.raku85
2 files changed, 118 insertions, 0 deletions
diff --git a/challenge-343/mark-anderson/raku/ch-1.raku b/challenge-343/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..653c6bfaa7
--- /dev/null
+++ b/challenge-343/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,33 @@
+#!/usr/bin/env raku
+use Test;
+
+is zero-friend(4, 2, -1, 3, -2), 1;
+is zero-friend(-5, 5, -3, 3, -1, 1), 1;
+is zero-friend(7, -3, 0, 2, -8), 0;
+is zero-friend(-2, -5, -1, -8), 1;
+is zero-friend(-2, 2, -4, 4, -1, 1), 1;
+
+is zero-friend-alt(4, 2, -1, 3, -2), -1;
+is zero-friend-alt(-5, 5, -3, 3, -1, 1), 1;
+is zero-friend-alt(7, -3, 0, 2, -8), 0;
+is zero-friend-alt(-2, -5, -1, -8), -1;
+is zero-friend-alt(-2, 2, -4, 4, -1, 1), 1;
+
+sub zero-friend(+@nums)
+{
+ @nums.classify({ .sign }, :as{ .abs })
+ .values
+ .flat(:hammer)
+ .min
+}
+
+# I think this alternate solution matches the instructions better.
+# I meant to email Mohammad for clarification before the deadline
+# but I forgot.
+
+sub zero-friend-alt(+@nums)
+{
+ my %c := { -1 => [], 0 => [], 1 => [] }
+ %c = @nums.classify: { .sign }, :into(%c);
+ (%c<-1>.max, %c<0>.min, %c<1>.min).sort({ .abs, -.sign }).head
+}
diff --git a/challenge-343/mark-anderson/raku/ch-2.raku b/challenge-343/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..f5077b81b2
--- /dev/null
+++ b/challenge-343/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,85 @@
+#!/usr/bin/env raku
+use Test;
+
+is champion-team([0,1,1],
+ [0,0,1],
+ [0,0,0]), 0;
+
+is champion-team([0,1,0,0],
+ [0,0,0,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