diff options
Diffstat (limited to 'challenge-253')
| -rwxr-xr-x | challenge-253/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-253/feng-chang/raku/ch-2.raku | 9 | ||||
| -rwxr-xr-x | challenge-253/feng-chang/raku/test.raku | 36 |
3 files changed, 50 insertions, 0 deletions
diff --git a/challenge-253/feng-chang/raku/ch-1.raku b/challenge-253/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..dc4847bcd7 --- /dev/null +++ b/challenge-253/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN($sep, *@strings); + +put @strings».split($sep, :skip-empty).flat.grep(?*).join(' '); diff --git a/challenge-253/feng-chang/raku/ch-2.raku b/challenge-253/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..3b23e1f193 --- /dev/null +++ b/challenge-253/feng-chang/raku/ch-2.raku @@ -0,0 +1,9 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $s); + +use MONKEY-SEE-NO-EVAL; +my @matrix; +EVAL "@matrix = $s"; + +put @matrix.pairs.sort({ .value.sum, +.key })».key.join(', '); diff --git a/challenge-253/feng-chang/raku/test.raku b/challenge-253/feng-chang/raku/test.raku new file mode 100755 index 0000000000..5c2056ccef --- /dev/null +++ b/challenge-253/feng-chang/raku/test.raku @@ -0,0 +1,36 @@ +#!/bin/env raku + +# The Weekly Challenge 253 +use Test; + +sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) { + my ($expect, $assertion) = @input.splice(*-2, 2); + my $p = run $script, |@input, :out; + if $deeply { + is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion; + } else { + is $p.out.slurp(:close).chomp, $expect, $assertion; + } +} + +# Task 1, Split Strings +pwc-test './ch-1.raku', + |<. one.two.three four.five six>, + 'one two three four five six', + 'Split Strings: @words = ("one.two.three", "four.five", "six"), $separator = "." => "one","two","three","four","five","six"'; +pwc-test './ch-1.raku', + |<$ $perl$$ $$raku$>, + 'perl raku', + 'Split Strings: @words = ("$perl$$", "$$raku$"), $separator = "$" => "perl","raku"'; + +# Task 2, Weakest Row +pwc-test './ch-2.raku', + '[1,1,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,1,0,0,0],[1,1,1,1,1]', + '2, 0, 3, 1, 4', + 'Weakest Row: [[1,1,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,1,0,0,0],[1,1,1,1,1]] => (2, 0, 3, 1, 4)'; +pwc-test './ch-2.raku', + '[1,0,0,0],[1,1,1,1],[1,0,0,0],[1,0,0,0]', + '0, 2, 3, 1', + 'Weakest Row: [[1,0,0,0],[1,1,1,1],[1,0,0,0],[1,0,0,0]] => (0, 2, 3, 1)'; + +done-testing; |
