aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-23 15:52:57 +0100
committerGitHub <noreply@github.com>2024-04-23 15:52:57 +0100
commit59d11166c24beb75c69862f9916592a4fadfb8ce (patch)
tree8d95e26ebb248107b1f62cccec4cc6011fbb2caf
parent4672c0618e09d918c70ef3d009eed47ebbf192fd (diff)
parente4bded110f948c36749cccd8429fcaa112f4c677 (diff)
downloadperlweeklychallenge-club-59d11166c24beb75c69862f9916592a4fadfb8ce.tar.gz
perlweeklychallenge-club-59d11166c24beb75c69862f9916592a4fadfb8ce.tar.bz2
perlweeklychallenge-club-59d11166c24beb75c69862f9916592a4fadfb8ce.zip
Merge pull request #9973 from andemark/challenge-266
Challenge 266
-rw-r--r--challenge-266/mark-anderson/raku/ch-1.raku19
-rw-r--r--challenge-266/mark-anderson/raku/ch-2.raku187
2 files changed, 206 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..9a2bbd201f
--- /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 translation 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..0cca03e98e
--- /dev/null
+++ b/challenge-266/mark-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3,0,0],
+ [0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,8,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 := |((^@m) Z (^@m)), |((0...@m.end) Z (@m.end...0));
+
+ my @replace = 0 xx $diags;
+
+ @replace[@replace.elems div 4] = 1 if @m.end %% 2;
+
+ my @diags = ($diags Z @replace).map(-> (($row, $col), $replace)
+ {
+ @m[$row].splice($col,1,$replace).head
+ });
+
+ so all(all |@diags, none @m[*;*])
+}