diff options
| -rw-r--r-- | challenge-344/mark-anderson/raku/ch-1.raku | 13 | ||||
| -rw-r--r-- | challenge-344/mark-anderson/raku/ch-2.raku | 23 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-344/mark-anderson/raku/ch-1.raku b/challenge-344/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..8090d92bb2 --- /dev/null +++ b/challenge-344/mark-anderson/raku/ch-1.raku @@ -0,0 +1,13 @@ +#!/usr/bin/env raku +use Test; + +is array-form-compute((1,2,3,4), 12), (1,2,4,6); +is array-form-compute((2,7,4), 181), (4,5,5); +is array-form-compute((9,9,9), 1), (1,0,0,0); +is array-form-compute((1,0,0,0,0), 9999), (1,9,9,9,9); +is array-form-compute((0,), 1000), (1,0,0,0); + +sub array-form-compute(@ints, $x) +{ + .comb given @ints.join + $x +} diff --git a/challenge-344/mark-anderson/raku/ch-2.raku b/challenge-344/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..6aa924e9b2 --- /dev/null +++ b/challenge-344/mark-anderson/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/usr/bin/env raku +use Test; + +ok array-formation([[2,3],[1],[4]], [1,2,3,4]); +nok array-formation([[1,3],[2,4]], [1,2,3,4]); +ok array-formation([[9,1],[5,8],[2]], [5,8,2,9,1]); +nok array-formation([[1],[3]], [1,2,3]); +ok array-formation([[7,4,6]], [7,4,6]); +ok array-formation([[1],[2,33],[33,4],[2,33,4,5],[7],[1,2]], + [1,2,33,4,5,7,33,4,2,33,1,2]); + +sub array-formation(@source, @target) +{ + my $target = @target.Str; + + for @source.sort(-*.elems) + { + $target .= subst(/$_/, 'X'); + return False unless $/ + } + + $target !~~ /<digit>/ +} |
