From 47f90edd7f8967abf70a611862f40ed05a05ec9a Mon Sep 17 00:00:00 2001 From: Polgár Márton Date: Tue, 8 Nov 2022 00:44:19 +0100 Subject: Weeklies no. 190 by 2colours --- challenge-190/2colours/raku/ch-1.raku | 11 +++++++++++ challenge-190/2colours/raku/ch-2.raku | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 challenge-190/2colours/raku/ch-1.raku create mode 100755 challenge-190/2colours/raku/ch-2.raku 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 -- cgit