diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2024-01-23 16:50:07 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2024-01-23 16:50:07 +0800 |
| commit | b272c7f737b5969c4ce12783dc47a8d7a6af6574 (patch) | |
| tree | 1537379f625e816e8852f56ff79d8c9d0773835a | |
| parent | 03ba5f1a88a527302c5c9fdb0fb5c531a65b1719 (diff) | |
| download | perlweeklychallenge-club-b272c7f737b5969c4ce12783dc47a8d7a6af6574.tar.gz perlweeklychallenge-club-b272c7f737b5969c4ce12783dc47a8d7a6af6574.tar.bz2 perlweeklychallenge-club-b272c7f737b5969c4ce12783dc47a8d7a6af6574.zip | |
challenge 253, raku solutions
| -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; |
