aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-249/wambash/raku/ch-2.raku21
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-249/wambash/raku/ch-2.raku b/challenge-249/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..3f55d70bb4
--- /dev/null
+++ b/challenge-249/wambash/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+
+sub DI-string-match ($s) {
+ my @si = $s.comb;
+ my @perm = 0 .. @si.elems;
+
+ my @b = @si.map: { $_ eq 'I' ?? @perm.shift !! @perm.pop }
+ |@b, @perm.shift
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply DI-string-match('IDID'), (0,4,1,3,2);
+ is-deeply DI-string-match('III'), (0,1,2,3);
+ is-deeply DI-string-match('DDI'), (3,2,0,1);
+ done-testing;
+}
+
+multi MAIN ($s) {
+ say DI-string-match $s
+}