diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-11-09 19:42:52 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-09 19:42:52 +0000 |
| commit | 2d42816ca5f72d719565383a47111e17dca68bc7 (patch) | |
| tree | e9870887a87614318690a9499af9efa63c14b436 | |
| parent | 810dec7dffb8b2f6dae6693ee766e03495df108c (diff) | |
| parent | 47f90edd7f8967abf70a611862f40ed05a05ec9a (diff) | |
| download | perlweeklychallenge-club-2d42816ca5f72d719565383a47111e17dca68bc7.tar.gz perlweeklychallenge-club-2d42816ca5f72d719565383a47111e17dca68bc7.tar.bz2 perlweeklychallenge-club-2d42816ca5f72d719565383a47111e17dca68bc7.zip | |
Merge pull request #7054 from 2colours/branch-for-challenge-190
Weeklies no. 190 by 2colours
| -rwxr-xr-x | challenge-190/2colours/raku/ch-1.raku | 11 | ||||
| -rwxr-xr-x | challenge-190/2colours/raku/ch-2.raku | 26 |
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-190/2colours/raku/ch-1.raku b/challenge-190/2colours/raku/ch-1.raku new file mode 100755 index 0000000000..4e557f39c2 --- /dev/null +++ b/challenge-190/2colours/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku + +subset AsciiWord of Str where /^ <[a..zA..Z]>* $/; + +sub MAIN(AsciiWord $s) { + $s andthen + $_ eq any(.tclc, .lc, .uc) andthen + .so + .Int + .say; +}
\ No newline at end of file diff --git a/challenge-190/2colours/raku/ch-2.raku b/challenge-190/2colours/raku/ch-2.raku new file mode 100755 index 0000000000..8aaa409c5f --- /dev/null +++ b/challenge-190/2colours/raku/ch-2.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku + +#NOTE: disallowing leading zeros and completely empty input + +subset Encoding of Str where /^ <[1..9]><[0..9]>* $/; + +use experimental :cached; + +sub nth-letter($n) { chr(ord('A') + $n - 1) } + + +proto decodings(@content) is cached {*} +multi decodings(() --> '') {} +multi decodings(('0', ) --> Empty) {} +multi decodings(($codepoint, )) { nth-letter $codepoint } +multi decodings(('0', $, **@) --> Empty) {} +multi decodings(($first, $next, **@rest)) { + slip (nth-letter($first) <<~<< decodings(($next, |@rest))), + slip (.&nth-letter <<~<< decodings(@rest) if $_ <= 26 given $first ~ $next) +} + + + +sub MAIN(Encoding $s) { + $s.comb.&decodings.sort.join(', ').say; +}
\ No newline at end of file |
