aboutsummaryrefslogtreecommitdiff
path: root/challenge-190
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2022-11-07 09:37:13 +0000
committerMark <53903062+andemark@users.noreply.github.com>2022-11-07 09:37:13 +0000
commit1b25498f4abe3f5dba99bc8b1190263c14b87ffe (patch)
tree29663c87a328692222804508739f9aaee9c7ecc4 /challenge-190
parent74cc850f3e4d5523ec357f0c8eb3852a1cd5d647 (diff)
downloadperlweeklychallenge-club-1b25498f4abe3f5dba99bc8b1190263c14b87ffe.tar.gz
perlweeklychallenge-club-1b25498f4abe3f5dba99bc8b1190263c14b87ffe.tar.bz2
perlweeklychallenge-club-1b25498f4abe3f5dba99bc8b1190263c14b87ffe.zip
Challenge 190 Solutions (Raku)
Diffstat (limited to 'challenge-190')
-rw-r--r--challenge-190/mark-anderson/raku/ch-1.raku12
-rw-r--r--challenge-190/mark-anderson/raku/ch-2.raku24
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-190/mark-anderson/raku/ch-1.raku b/challenge-190/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..16b5ff297a
--- /dev/null
+++ b/challenge-190/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/usr/bin/env raku
+use Test;
+
+ok capital-detection("Perl");
+ok capital-detection("TPF");
+nok capital-detection("PyThon");
+ok capital-detection("raku");
+
+sub capital-detection($s)
+{
+ any($s eq $s.tclc, $s eq $s.lc, $s eq $s.uc)
+}
diff --git a/challenge-190/mark-anderson/raku/ch-2.raku b/challenge-190/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..be1685915e
--- /dev/null
+++ b/challenge-190/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,24 @@
+#!/usr/bin/env raku
+use Test;
+
+is-deeply decode-counts(11), < AA K >;
+is-deeply decode-counts(1115), < AAAE AAO AKE KAE KO >;
+is-deeply decode-counts(127), < ABG LG >;
+
+# Not sure how to deal with zeros but this is what the program does.
+is-deeply decode-counts(1002001), < ABA ATA JBA JTA >;
+
+sub decode-counts($n)
+{
+ sub composition($_)
+ {
+ gather .fmt('%0' ~ $n.chars ~ 'b') ~~ m:g/(.)$0* <?{ take $/.pos - $/.from }>/
+ }
+
+ sort map
+ {
+ my $c := $n.comb.rotor(composition($_))>>.join>>.Int;
+ next unless all($c) ~~ 1..26;
+ [~] $c.map({ chr($_+64) });
+ }, ^2**($n.chars-1)
+}