aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-220/mark-anderson/raku/ch-1.raku10
-rw-r--r--challenge-220/mark-anderson/raku/ch-2.raku23
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-220/mark-anderson/raku/ch-1.raku b/challenge-220/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..9f4ce69b18
--- /dev/null
+++ b/challenge-220/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply common-characters(<Perl Rust Raku>), ("r",);
+is-deeply common-characters(<love live leave>), <e l v>;
+
+sub common-characters
+{
+ sort .keys given [(&)] @^a>>.lc>>.comb
+}
diff --git a/challenge-220/mark-anderson/raku/ch-2.raku b/challenge-220/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..99b1091536
--- /dev/null
+++ b/challenge-220/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply squareful(1, 17, 8), ((1, 8, 17), (17, 8, 1));
+is-deeply squareful(2, 2, 2), ((2, 2, 2),);
+
+sub squareful(+@a)
+{
+ @a.permutations.unique(with => &[eqv])
+ .grep({ all(.rotor(2 => -1)).sum.sqrt.narrow ~~ UInt })
+}
+
+=begin alternate
+sub squareful(+@a)
+{
+ my $s = @a.sort.tail(2).sum;
+
+ my $squares := (0..$s Z* 0..$s).List;
+
+ @a.permutations.unique(with => &[eqv])
+ .grep({ .rotor(2 => -1)>>.sum (<=) $squares })
+}
+=end alternate