aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2023-03-20 08:16:35 +0000
committerMark <53903062+andemark@users.noreply.github.com>2023-03-20 08:16:35 +0000
commit3f1b014fba8655d40a3a750d1bd6266fc91a0b74 (patch)
treec0fe96f458068560b0286869c5717921bc32d3a3
parent9c5cd2108a8f6cf8b793c28051fdf8d767a4c8a9 (diff)
downloadperlweeklychallenge-club-3f1b014fba8655d40a3a750d1bd6266fc91a0b74.tar.gz
perlweeklychallenge-club-3f1b014fba8655d40a3a750d1bd6266fc91a0b74.tar.bz2
perlweeklychallenge-club-3f1b014fba8655d40a3a750d1bd6266fc91a0b74.zip
initial 209 (Raku)
-rw-r--r--challenge-209/mark-anderson/raku/ch-1.raku21
-rw-r--r--challenge-209/mark-anderson/raku/ch-2.raku49
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-209/mark-anderson/raku/ch-1.raku b/challenge-209/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..dac544bd91
--- /dev/null
+++ b/challenge-209/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+use Test;
+
+ok special-bit-chars(0);
+ok special-bit-chars(1,0,0);
+ok special-bit-chars(1,0,1,1,0);
+ok special-bit-chars(0,0,0,0,0,0);
+ok special-bit-chars(0,1,0,1,0,0);
+ok special-bit-chars(0,1,0,1,0,0);
+
+nok special-bit-chars(1,1,1,0);
+nok special-bit-chars(1,1,1,1,1,0);
+nok special-bit-chars(1,1,0,0,1,0);
+nok special-bit-chars(1,0,1,0,1,0);
+nok special-bit-chars(0,0,0,0,1,0);
+
+sub special-bit-chars(+$a)
+{
+ my $r = / 0+ | [10]+ | [11]+ /;
+ $a.join ~~ /^ $r* 0 $/
+}
diff --git a/challenge-209/mark-anderson/raku/ch-2.raku b/challenge-209/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..5248fc8c76
--- /dev/null
+++ b/challenge-209/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,49 @@
+#!/usr/bin/env raku
+
+merge-accounts([
+ ["A", "a1@a.com", "a2@a.com"],
+ ["B", "b1@b.com"],
+ ["A", "a3@a.com", "a1@a.com"]
+ ]);
+
+merge-accounts([
+ ["A", "a1@a.com", "a2@a.com"],
+ ["B", "b1@b.com"],
+ ["A", "a3@a.com"],
+ ["B", "b2@b.com", "b1@b.com"]
+ ]);
+
+merge-accounts([
+ ["C", "c2@c.com"],
+ ["C", "c1@c.com", "c4@c.com"],
+ ["A", "a1@a.com", "a2@a.com"],
+ ["B", "b1@b.com"],
+ ["A", "a3@a.com"],
+ ["C", "c1@c.com", "c3@c.com"],
+ ["B", "b2@b.com", "b1@b.com"],
+ ["A", "a3@a.com", "a4@a.com"],
+ ["B", "b3@b.com"];
+ ]);
+
+sub merge-accounts(@accounts)
+{
+ my @a = @accounts.classify({ .[0] }, :as{ .[1..*] });
+
+ for @a.sort(*.key)
+ {
+ my $key = .key;
+ my @value = .value>>.Array;
+
+ my @g = gather
+ {
+ while @value
+ {
+ my @v := @value.shift;
+ my $k = @value.first({ $_ (&) @v }, :k);
+ $k.defined ?? @value[$k].append(@v) .= unique !! take @v;
+ }
+ }
+
+ say $key => @g>>.sort;
+ }
+}