diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2024-07-15 16:30:31 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2024-07-15 16:30:31 +0800 |
| commit | a325ce0ca92e30440c78805dca556487ea52c0de (patch) | |
| tree | 4d100ac71c9e04ad4396aa2ff9b7540bc66be4b6 | |
| parent | 18e08d1c65808d14894933b1a14312403a3fb8d6 (diff) | |
| download | perlweeklychallenge-club-a325ce0ca92e30440c78805dca556487ea52c0de.tar.gz perlweeklychallenge-club-a325ce0ca92e30440c78805dca556487ea52c0de.tar.bz2 perlweeklychallenge-club-a325ce0ca92e30440c78805dca556487ea52c0de.zip | |
challenge 278, raku solutions
| -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 |
3 files changed, 42 insertions, 0 deletions
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"'; |
