diff options
| author | Humberto Massa <humbertomassa@gmail.com> | 2022-11-08 08:28:12 -0300 |
|---|---|---|
| committer | Humberto Massa <humbertomassa@gmail.com> | 2022-11-08 08:28:12 -0300 |
| commit | 87997719ba499f2b60ab4307bb4b56a5a4eb9f00 (patch) | |
| tree | 419f01338e123193a570bc41cb82f363942441be | |
| parent | 74cc850f3e4d5523ec357f0c8eb3852a1cd5d647 (diff) | |
| download | perlweeklychallenge-club-87997719ba499f2b60ab4307bb4b56a5a4eb9f00.tar.gz perlweeklychallenge-club-87997719ba499f2b60ab4307bb4b56a5a4eb9f00.tar.bz2 perlweeklychallenge-club-87997719ba499f2b60ab4307bb4b56a5a4eb9f00.zip | |
decode-counts gave me some trouble
| -rw-r--r-- | challenge-190/massa/raku/ch-1.raku | 31 | ||||
| -rw-r--r-- | challenge-190/massa/raku/ch-2.raku | 39 |
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-190/massa/raku/ch-1.raku b/challenge-190/massa/raku/ch-1.raku new file mode 100644 index 0000000000..1de5f81ce8 --- /dev/null +++ b/challenge-190/massa/raku/ch-1.raku @@ -0,0 +1,31 @@ + +#!/usr/bin/env raku + +=begin pod + +Week 190: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-190 + +Task #1: Capital Detection + + Write a script to find out if the usage of Capital is appropriate if it satisfies at least one of the following rules: + + 1) Only first letter is capital and all others are small. + 2) Every letter is small. + 3) Every letter is capital. + +=end pod + +use Test; + +my regex capital-detection { ^ [ <upper> <lower>* | <upper>+ | <lower>+ ] $ } + +ok 'Perl' ~~ /<capital-detection>/; +ok 'TPF' ~~ /<capital-detection>/; +nok 'PyThon' ~~ /<capital-detection>/; +ok 'raku' ~~ /<capital-detection>/; + +done-testing; + + diff --git a/challenge-190/massa/raku/ch-2.raku b/challenge-190/massa/raku/ch-2.raku new file mode 100644 index 0000000000..f59da3aef9 --- /dev/null +++ b/challenge-190/massa/raku/ch-2.raku @@ -0,0 +1,39 @@ + +#!/usr/bin/env raku + +=begin pod + +Week 190: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-190 + +Task #2: Decoded List + + You are given an encoded string consisting of a sequence of numeric + characters: C<0..9>, C<$s>. + + Write a script to find the all valid different decodings in sorted order. + + Encoding is simply done by mapping A,B,C,D,… to 1,2,3,4,… etc. + + +=end pod + +use Test; + +is-deeply <AA K>, decoded-list 11; +is-deeply <AAAE AAO AKE KAE KO>, decoded-list 1115; +is-deeply <ABG LG>, decoded-list 127; + +done-testing; + +sub decoded-list(Str() $_) { + combinations(.chars + 1, .chars div 2 .. .chars + 1)».\ # all the combinations + rotor(2=>-1)».Array».map({.[0] ..^ .[1]})».Array.\ # transformed in contiguous subsets + grep(*».elems.all == 1|2).\ # subsets must be of size one or two + grep(*».elems.sum == .chars)».\ # and they must cover the whole string + map(-> @s { .comb[@s].join })».\ # map to the original string's chars + trans([1..26] => ['A'..'Z'])».join.\ # decode + sort.unique +} + |
