diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-07-16 11:42:05 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-16 11:42:05 +0100 |
| commit | 19a4cb8fee3c267bfaace7516b8bde355add095f (patch) | |
| tree | 6eebc414b200332dd15475ed206c0067c92aaba9 /challenge-278 | |
| parent | 5f2a9cdc45415d2f96ea71b2f7c3b6d96d6b5213 (diff) | |
| parent | a325ce0ca92e30440c78805dca556487ea52c0de (diff) | |
| download | perlweeklychallenge-club-19a4cb8fee3c267bfaace7516b8bde355add095f.tar.gz perlweeklychallenge-club-19a4cb8fee3c267bfaace7516b8bde355add095f.tar.bz2 perlweeklychallenge-club-19a4cb8fee3c267bfaace7516b8bde355add095f.zip | |
Merge pull request #10433 from seaker/master
Challenge 278, Feng Chang's Raku solutions
Diffstat (limited to 'challenge-278')
| -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"'; |
