diff options
| -rwxr-xr-x | challenge-245/feng-chang/raku/ch-1.raku | 6 | ||||
| -rwxr-xr-x | challenge-245/feng-chang/raku/ch-2.raku | 5 | ||||
| -rwxr-xr-x | challenge-245/feng-chang/raku/test.raku | 33 |
3 files changed, 44 insertions, 0 deletions
diff --git a/challenge-245/feng-chang/raku/ch-1.raku b/challenge-245/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..d12847286b --- /dev/null +++ b/challenge-245/feng-chang/raku/ch-1.raku @@ -0,0 +1,6 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $langs, Str:D $popular); + +my %langs = $langs.words Z=> +«$popular.words; +put %langs.keys.sort({ %langs{$_} }); diff --git a/challenge-245/feng-chang/raku/ch-2.raku b/challenge-245/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..4cba0247de --- /dev/null +++ b/challenge-245/feng-chang/raku/ch-2.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@ints where @ints.all ≥ 0); + +put @ints.combinations.grep(*.join %% 3).map({ .permutations.map(*.join) }).flat.max || -1; diff --git a/challenge-245/feng-chang/raku/test.raku b/challenge-245/feng-chang/raku/test.raku new file mode 100755 index 0000000000..a14c97b30c --- /dev/null +++ b/challenge-245/feng-chang/raku/test.raku @@ -0,0 +1,33 @@ +#!/bin/env raku + +# The Weekly Challenge 245 +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, Sort Language +pwc-test './ch-1.raku', + 'perl c python', + '2 1 3', + 'c perl python', + 'Sort Language: @lang = ("perl", "c", "python"), @popularity = (2, 1, 3) => ("c", "perl", "python")'; +pwc-test './ch-1.raku', + 'c++ haskell java', + '1 3 2', + 'c++ java haskell', + 'Sort Language: @lang = ("c++", "haskell", "java"), @popularity = (1, 3, 2) => ("c++", "java", "haskell")'; + +# Task 2, Largest of Three +pwc-test './ch-2.raku', |<8 1 9>, 981, 'Largest of Three: (8, 1, 9) => 981'; +pwc-test './ch-2.raku', |<8 6 7 1 0>, 8760, 'Largest of Three: (8, 6, 7, 1, 0) => 8760'; +pwc-test './ch-2.raku', 1, -1, 'Largest of Three: (1) => -1'; + +done-testing; |
