aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-11-09 19:42:52 +0000
committerGitHub <noreply@github.com>2022-11-09 19:42:52 +0000
commit2d42816ca5f72d719565383a47111e17dca68bc7 (patch)
treee9870887a87614318690a9499af9efa63c14b436
parent810dec7dffb8b2f6dae6693ee766e03495df108c (diff)
parent47f90edd7f8967abf70a611862f40ed05a05ec9a (diff)
downloadperlweeklychallenge-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-xchallenge-190/2colours/raku/ch-1.raku11
-rwxr-xr-xchallenge-190/2colours/raku/ch-2.raku26
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