diff options
| author | Jan Krňávek <Jan.Krnavek@gmail.com> | 2024-07-19 08:49:05 +0200 |
|---|---|---|
| committer | Jan Krňávek <Jan.Krnavek@gmail.com> | 2024-07-19 08:49:05 +0200 |
| commit | 96df6138552848f2ffe27865480f5302436c0df7 (patch) | |
| tree | dcb17b69672ad464d3b9d24c1299633b9ad2406c | |
| parent | aa4b8cba9159de89df615ce53b3ace6f57df0ca2 (diff) | |
| download | perlweeklychallenge-club-96df6138552848f2ffe27865480f5302436c0df7.tar.gz perlweeklychallenge-club-96df6138552848f2ffe27865480f5302436c0df7.tar.bz2 perlweeklychallenge-club-96df6138552848f2ffe27865480f5302436c0df7.zip | |
solutions week 278
| -rw-r--r-- | challenge-278/wambash/raku/ch-1.raku | 22 | ||||
| -rw-r--r-- | challenge-278/wambash/raku/ch-2.raku | 20 |
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-278/wambash/raku/ch-1.raku b/challenge-278/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..06b8c3fe1c --- /dev/null +++ b/challenge-278/wambash/raku/ch-1.raku @@ -0,0 +1,22 @@ +#!/usr/bin/env raku + +sub sort-string ($str) { + $str + andthen .match: /(<alpha>+)(\d+)/, :g + andthen .sort: *.[1] + andthen .map: *.[0] + andthen .Str +} + +multi MAIN (Bool :test($)!) { + use Test; + is sort-string('and2 Raku3 cousins5 Perl1 are4'),'Perl and Raku are cousins'; + is sort-string('guest6 Python1 most4 the3 popular5 is2 language7'), 'Python is the most popular guest language'; + is sort-string('Challenge3 The1 Weekly2'), 'The Weekly Challenge'; + is sort-string('b2 d4 c3 a1'), 'a b c d'; + done-testing; +} + +multi MAIN ($str) { + say sort-string $str +} diff --git a/challenge-278/wambash/raku/ch-2.raku b/challenge-278/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..26c2d1d447 --- /dev/null +++ b/challenge-278/wambash/raku/ch-2.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + +sub reverse-word ($str, :$char) { + $str.subst( + / (.)*? <after $char> /, + { [~] .[0].sort } + ) +} + +multi MAIN (Bool :test($)!) { + use Test; + is reverse-word('challenge', :char<e>), 'acehllnge'; + is reverse-word('programming', :char<a>), 'agoprrmming'; + is reverse-word('champion', :char<b>), 'champion'; + done-testing; +} + +multi MAIN ($str,:$char) { + say reverse-word $str,:$char +} |
