aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPolgár Márton <polgar@astron.hu>2022-11-08 00:44:19 +0100
committerPolgár Márton <polgar@astron.hu>2022-11-08 00:44:19 +0100
commit47f90edd7f8967abf70a611862f40ed05a05ec9a (patch)
treefc13153c3919ef52b268e3cc12f52d8f0365e4d4
parent74cc850f3e4d5523ec357f0c8eb3852a1cd5d647 (diff)
downloadperlweeklychallenge-club-47f90edd7f8967abf70a611862f40ed05a05ec9a.tar.gz
perlweeklychallenge-club-47f90edd7f8967abf70a611862f40ed05a05ec9a.tar.bz2
perlweeklychallenge-club-47f90edd7f8967abf70a611862f40ed05a05ec9a.zip
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