aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-082/simon-proctor/raku/ch-2.raku12
1 files changed, 12 insertions, 0 deletions
diff --git a/challenge-082/simon-proctor/raku/ch-2.raku b/challenge-082/simon-proctor/raku/ch-2.raku
new file mode 100644
index 0000000000..916919eb9c
--- /dev/null
+++ b/challenge-082/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,12 @@
+#!/usr/bin/env raku
+
+use v6;
+
+#| Given three strings return 1 if the third string ($C) can be made by interleaving $A and $B
+sub MAIN ( Str $A, Str $B, Str $C ) {
+ ( any( |possible-interleaves($A,$B), |possible-interleaves($B,$A) ) ~~ $C ).Int.say;
+}
+
+sub possible-interleaves( Str $out, Str $sub ) {
+ (0..$out.codes).map( { my $x = $out; $x.substr-rw($_,0) = $sub; $x } )
+}