aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-308/mark-anderson/raku/ch-1.raku11
-rw-r--r--challenge-308/mark-anderson/raku/ch-2.raku22
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-308/mark-anderson/raku/ch-1.raku b/challenge-308/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..172e29c8e6
--- /dev/null
+++ b/challenge-308/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,11 @@
+#!/usr/bin/env raku
+use Test;
+
+is count-common(<perl weekly challenge>, <raku weekly challenge>), 2;
+is count-common(<perl raku python>, <python java>), 1;
+is count-common(<guest contribution>, <fun weekly challenge>), 0;
+
+sub count-common(@a, @b)
+{
+ +(@a ∩ @b)
+}
diff --git a/challenge-308/mark-anderson/raku/ch-2.raku b/challenge-308/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..c2e95667d1
--- /dev/null
+++ b/challenge-308/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply decode-xor([1,2,3], 1), (1,0,2,1);
+is-deeply decode-xor([6,2,7,3], 4), (4,2,0,7,4);
+
+sub decode-xor(@e, $i)
+{
+ my $c;
+ ($i, $i+^@e[$c++], {$^a+^@e[$c++]}...*).head(@e+1)
+}
+
+=begin alternate-solution
+sub decode-xor(@encoded, $initial is copy)
+{
+ gather for @encoded
+ {
+ once take $initial;
+ take $initial +^= $_
+ }
+}
+=end alternate-solution