aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-275/mark-anderson/raku/ch-1.raku15
-rw-r--r--challenge-275/mark-anderson/raku/ch-2.raku21
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-275/mark-anderson/raku/ch-1.raku b/challenge-275/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..2fd24dc19a
--- /dev/null
+++ b/challenge-275/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,15 @@
+#!/usr/bin/env raku
+use Test;
+
+is broken-keys("Perl Weekly Challenger", <l a>), 0;
+is broken-keys("Perl and Raku", <a>), 1;
+is broken-keys("Well done team PWC", <l o>), 2;
+is broken-keys("The joys of polyglottism", <T>), 2;
+
+sub broken-keys
+{
+ my $s = $^a.fc;
+ my $k = $^b>>.fc;
+
+ + $s.words.grep({ .comb.any !~~ $k.any })
+}
diff --git a/challenge-275/mark-anderson/raku/ch-2.raku b/challenge-275/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..412bfea82f
--- /dev/null
+++ b/challenge-275/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+use Test;
+
+is replace-digits('a1c1e1'), 'abcdef';
+is replace-digits('a1b2c3d4'), 'abbdcfdh';
+is replace-digits('b2b'), 'bdb';
+is replace-digits('a16z'), 'abgz';
+is replace-digits('a16bzd7'), 'abgdk';
+
+sub replace-digits($s)
+{
+ my ($head, $tail) = $s.split(/ <.alpha>+ $ /, :v);
+
+ my @result = do for $head.split(/\d+/, :v:skip-empty).batch(2)
+ {
+ my $char = .head ~~ / <.alpha> $ /;
+ $char ~ [~] .tail.comb.map({ chr($char.ord + $_) })
+ }
+
+ ([~] @result) ~ ($tail or Empty)
+}