aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2024-04-22 09:00:07 +0000
committerMark <53903062+andemark@users.noreply.github.com>2024-04-22 09:00:07 +0000
commit57282e939238dbd4fddfe636eab05c953f48d41a (patch)
tree73dd4c782172c933d204ae8a167eff0ed379894a
parentaed41ed119210ab32e32b82af8039f2c1457726b (diff)
downloadperlweeklychallenge-club-57282e939238dbd4fddfe636eab05c953f48d41a.tar.gz
perlweeklychallenge-club-57282e939238dbd4fddfe636eab05c953f48d41a.tar.bz2
perlweeklychallenge-club-57282e939238dbd4fddfe636eab05c953f48d41a.zip
Challenge 266 Solutions (Raku)
-rw-r--r--challenge-266/mark-anderson/raku/ch-1.raku19
-rw-r--r--challenge-266/mark-anderson/raku/ch-2.raku195
2 files changed, 214 insertions, 0 deletions
diff --git a/challenge-266/mark-anderson/raku/ch-1.raku b/challenge-266/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..1f01622531
--- /dev/null
+++ b/challenge-266/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply uncommon-words('Mango is sweet', 'Mango is sour'), ('sweet', 'sour'), 'example 1';
+is-deeply uncommon-words('Mango Mango', 'Orange'), ('Orange',), 'example 2';
+is-deeply uncommon-words('Mango is Mango', 'Orange is Orange'), (), 'example 3';
+
+sub uncommon-words($s1, $s2)
+{
+ # A literal solution using the one and none junctions
+ sub uw($s1, $s2)
+ {
+ my @s1 = $s1.words;
+ my @ones = @s1.unique.grep(one @s1);
+ @ones.grep(none $s2.words)
+ }
+
+ flat uw($s1, $s2), uw($s2, $s1)
+}
diff --git a/challenge-266/mark-anderson/raku/ch-2.raku b/challenge-266/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..dfe6bd7110
--- /dev/null
+++ b/challenge-266/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,195 @@
+#!/usr/bin/env raku
+use JSON::Fast;
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,0,0,0],
+ [0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,0],
+ [0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,9,0,0,0,0,0],
+ [0,0,0,0,0,0,6,0,0,0,0,0,0,0,9,0,0,0,0,0,0],
+ [0,0,0,0,0,0,0,9,0,0,0,0,0,7,0,0,0,0,0,0,0],
+ [0,0,0,0,0,0,0,0,7,0,0,0,9,0,0,0,0,0,0,0,0],
+ [0,0,0,0,0,0,0,0,0,8,0,1,0,0,0,0,0,0,0,0,0],
+ [0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,5],
+ [0,0,0,0,0,0,0,0,0,3,0,3,0,0,0,0,0,0,0,0,0],
+ [0,0,0,0,0,0,0,0,7,0,0,0,8,0,0,0,0,0,0,0,0],
+ [0,0,0,0,0,0,0,4,0,0,0,0,0,2,0,0,0,0,0,0,0],
+ [0,0,0,0,0,0,3,0,0,0,0,0,0,0,8,0,0,0,0,0,0],
+ [0,0,0,0,0,7,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0],
+ [0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,9,0,0,0,0],
+ [0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0],
+ [0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0],
+ [0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0],
+ [8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2],
+ ]),
+ '21 X 21 non-diagonal non-zero';
+
+sub X-matrix(+@m)
+{
+ my @diags = (0...@m.end) Z (@m.end...0);
+
+ # handle the center diagonal and middle row
+ if @diags.end %% 2
+ {
+ return False unless all so @m[.[0]].splice(.[1],1,0).head,
+ so none @m[.[0]]
+ given @diags.splice(@m.elems div 2,1).head
+
+ }
+
+ for @diags
+ {
+ return False unless all so @m[.[0]].splice(.[0],1,0).head,
+ so @m[.[0]].splice(.[1],1,0).head,
+ so none @m[.[0]]
+ }
+
+ True
+}