aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-344/barroff/raku/ch-2.p623
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-344/barroff/raku/ch-2.p6 b/challenge-344/barroff/raku/ch-2.p6
new file mode 100644
index 0000000000..9caaa0c14b
--- /dev/null
+++ b/challenge-344/barroff/raku/ch-2.p6
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+use v6.d;
+
+sub array-formation(@source, @target --> Bool) {
+ my Str $targetString = @target.Str;
+ return so map({ $_.Str }, @source.permutations).any eq $targetString;
+}
+
+#| Run test cases
+sub MAIN('test') {
+ use Test;
+ plan 5;
+
+ is array-formation(([2,3], [1], [4]), (1, 2, 3, 4)), True,
+ 'works for "(2,3], [1], [4])"';
+ is array-formation(([1,3], [2,4]), (1, 2, 3, 4)), False,
+ 'works for "([1,3], [2,4])"';
+ is array-formation(([9,1], [5,8], [2]), (5, 8, 2, 9, 1)), True,
+ 'works for "([9,1], [5,8], [2])"';
+ is array-formation(([1], [3]), (1, 2, 3)), False, 'works for "([1], [3])"';
+ is array-formation(([7,4,6]), (7, 4, 6)), True, 'works for "([7,4,6])"';
+}