aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-03-25 16:50:28 +0000
committerGitHub <noreply@github.com>2023-03-25 16:50:28 +0000
commit02ce9641f471478e53de2024f40401e9fb35cb2b (patch)
tree9ab893e2d2e3a9054afc36ba2be1602680a8941e
parent9c5cd2108a8f6cf8b793c28051fdf8d767a4c8a9 (diff)
parent284c2b7d28928a733a627fe213ff719cd3ff4e10 (diff)
downloadperlweeklychallenge-club-02ce9641f471478e53de2024f40401e9fb35cb2b.tar.gz
perlweeklychallenge-club-02ce9641f471478e53de2024f40401e9fb35cb2b.tar.bz2
perlweeklychallenge-club-02ce9641f471478e53de2024f40401e9fb35cb2b.zip
Merge pull request #7767 from andemark/branch-for-challenge-209
initial 209 (Raku)
-rw-r--r--challenge-209/mark-anderson/raku/ch-1.raku20
-rw-r--r--challenge-209/mark-anderson/raku/ch-2.raku63
2 files changed, 83 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..1584ebecc2
--- /dev/null
+++ b/challenge-209/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#!/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)
+{
+ $a.join ~~ /^ [ 0 | 10 | 11 ]* 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..b84ffb5aae
--- /dev/null
+++ b/challenge-209/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,63 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply merge-accounts([
+ [<A a1@a.com a2@a.com>],
+ [<B b1@b.com>],
+ [<A a3@a.com a1@a.com>]
+ ]),
+ [
+ [<A a1@a.com a2@a.com a3@a.com>],
+ [<B b1@b.com>]
+ ];
+
+is-deeply merge-accounts([
+ [<A a1@a.com a2@a.com>],
+ [<B b1@b.com>],
+ [<A a3@a.com>],
+ [<B b2@b.com b1@b.com>]
+ ]),
+ [
+ [<A a1@a.com a2@a.com>],
+ [<A a3@a.com>],
+ [<B b1@b.com b2@b.com>]
+ ];;
+
+is-deeply 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>],
+ [<B b4@b.com b5@b.com b6@b.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>];
+ ]),
+ [
+ [<A a1@a.com a2@a.com>],
+ [<A a3@a.com a4@a.com>],
+ [<B b4@b.com b5@b.com b6@b.com>],
+ [<B b1@b.com b2@b.com>],
+ [<B b3@b.com>],
+ [<C c2@c.com>],
+ [<C c1@c.com c3@c.com c4@c.com>]
+ ];
+
+sub merge-accounts(@accounts)
+{
+ my @a = @accounts.classify({ .[0] }, :as{ .[1..*] });
+
+ .Array given gather for @a.sort(*.key)
+ {
+ my @value = .value>>.Array;
+
+ while @value.shift -> @v
+ {
+ my $k = @value.first({ $_ (&) @v }, :k);
+ $k.defined ?? (@value[$k] = [(@value[$k] (|) @v).keys])
+ !! take [(.key, @v.sort.Slip)];
+ }
+ }
+}