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.raku27
2 files changed, 37 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..c34c232700
--- /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>>.comb>>.lc
+}
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..11ef39a5ef
--- /dev/null
+++ b/challenge-220/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,27 @@
+#!/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)
+{
+ gather for @a.permutations.unique(with => &[eqv])
+ {
+ .take if 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;
+
+ gather for @a.permutations.unique(with => &[eqv])
+ {
+ .take if .rotor(2 => -1)>>.sum (<) $squares
+ }
+}
+=end alternate