diff options
| -rwxr-xr-x | challenge-277/feng-chang/raku/ch-1a.raku | 2 | ||||
| -rwxr-xr-x | challenge-277/feng-chang/raku/test.raku | 6 | ||||
| -rwxr-xr-x | challenge-278/feng-chang/raku/ch-1.raku | 5 | ||||
| -rwxr-xr-x | challenge-278/feng-chang/raku/ch-2.raku | 8 | ||||
| -rwxr-xr-x | challenge-278/feng-chang/raku/test.raku | 29 |
5 files changed, 49 insertions, 1 deletions
diff --git a/challenge-277/feng-chang/raku/ch-1a.raku b/challenge-277/feng-chang/raku/ch-1a.raku index 00694b6dee..909e2a1cbf 100755 --- a/challenge-277/feng-chang/raku/ch-1a.raku +++ b/challenge-277/feng-chang/raku/ch-1a.raku @@ -2,4 +2,4 @@ unit sub MAIN(Str:D \s1, Str:D \s2); -put +[(&)] (s1, s2).map({ .cache.grep(.one) with .words }); +put +[(&)] (s1, s2).map({ .grep(.one) with .words.List }); diff --git a/challenge-277/feng-chang/raku/test.raku b/challenge-277/feng-chang/raku/test.raku index bdf1bbbc1e..9c16d2aa82 100755 --- a/challenge-277/feng-chang/raku/test.raku +++ b/challenge-277/feng-chang/raku/test.raku @@ -20,6 +20,12 @@ pwc-test './ch-1.raku', 'Perl and Python are very similar', 'Python is top in gu 'Count Common: <Perl and Python are very similar>, <Python is top in guest languages> => 1'; pwc-test './ch-1.raku', 'Perl is imperative Lisp is functional', 'Crystal is similar to Ruby', 0, 'Count Common: <Perl is imperative Lisp is functional>, <Crystal is similar to Ruby> => 0'; +pwc-test './ch-1a.raku', 'Perl is my friend', 'Perl and Raku are friend', 2, + 'Count Common: <Perl is my friend>, <Perl and Raku are friend> => 2'; +pwc-test './ch-1a.raku', 'Perl and Python are very similar', 'Python is top in guest languages', 1, + 'Count Common: <Perl and Python are very similar>, <Python is top in guest languages> => 1'; +pwc-test './ch-1a.raku', 'Perl is imperative Lisp is functional', 'Crystal is similar to Ruby', 0, + 'Count Common: <Perl is imperative Lisp is functional>, <Crystal is similar to Ruby> => 0'; # Task 2, Strong Pair pwc-test './ch-2.raku', <1 2 3 4 5>, 4, 'Strong Pair: 1, 2, 3, 4, 5 => 4'; diff --git a/challenge-278/feng-chang/raku/ch-1.raku b/challenge-278/feng-chang/raku/ch-1.raku new file mode 100755 index 0000000000..e7d2471600 --- /dev/null +++ b/challenge-278/feng-chang/raku/ch-1.raku @@ -0,0 +1,5 @@ +#!/bin/env raku + +unit sub MAIN(*@words); + +put @words.map({ ~.[1] => ~.[0] with .match(/(\D+)(\d+)/) }).Hash.sort(+*.key)ยป.value.join(' '); diff --git a/challenge-278/feng-chang/raku/ch-2.raku b/challenge-278/feng-chang/raku/ch-2.raku new file mode 100755 index 0000000000..fe02f16925 --- /dev/null +++ b/challenge-278/feng-chang/raku/ch-2.raku @@ -0,0 +1,8 @@ +#!/bin/env raku + +unit sub MAIN(Str:D $word is copy, Str:D \c where c.chars == 1); + +with $word.index(c) -> \idx { + $_ = .substr(0, idx+1).comb.sort.join ~ .substr(idx+1) with $word; +} +put $word; diff --git a/challenge-278/feng-chang/raku/test.raku b/challenge-278/feng-chang/raku/test.raku new file mode 100755 index 0000000000..65fc641102 --- /dev/null +++ b/challenge-278/feng-chang/raku/test.raku @@ -0,0 +1,29 @@ +#!/bin/env raku + +# The Weekly Challenge 278 +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 String +pwc-test './ch-1.raku', <and2 Raku3 cousins5 Perl1 are4>, 'Perl and Raku are cousins', + 'Sort String: "and2 Raku3 cousins5 Perl1 are4" => "Perl and Raku are cousins"'; +pwc-test './ch-1.raku', <guest6 Python1 most4 the3 popular5 is2 language7>, 'Python is the most popular guest language', + 'Sort String: "guest6 Python1 most4 the3 popular5 is2 language7" => "Python is the most popular guest language"'; +pwc-test './ch-1.raku', <Challenge3 The1 Weekly2>, 'The Weekly Challenge', + 'Sort String: "Challenge3 The1 Weekly2" => "The Weekly Challenge"'; +pwc-test './ch-1.raku', <j10 i9 h8 g7 f6 e5 d4 c3 b2 a1>, 'a b c d e f g h i j', + 'Sort String: "j10 i9 h8 g7 f6 e5 d4 c3 b2 a1" => "a b c d e f g h i j"'; + +# Task 2, Reverse Word +pwc-test './ch-2.raku', 'challenge', 'e', 'acehllnge', 'Reverse Word: $str="challenge", $char="e" => "acehllnge"'; +pwc-test './ch-2.raku', 'programming', 'a', 'agoprrmming', 'Reverse Word: $str="programming", $char="a" => "agoprrmming"'; +pwc-test './ch-2.raku', 'champion', 'b', 'champion', 'Reverse Word: $str="champion", $char="b" => "champion"'; |
