From 1b25498f4abe3f5dba99bc8b1190263c14b87ffe Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 7 Nov 2022 09:37:13 +0000 Subject: Challenge 190 Solutions (Raku) --- challenge-190/mark-anderson/raku/ch-1.raku | 12 ++++++++++++ challenge-190/mark-anderson/raku/ch-2.raku | 24 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 challenge-190/mark-anderson/raku/ch-1.raku create mode 100644 challenge-190/mark-anderson/raku/ch-2.raku 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* / + } + + sort map + { + my $c := $n.comb.rotor(composition($_))>>.join>>.Int; + next unless all($c) ~~ 1..26; + [~] $c.map({ chr($_+64) }); + }, ^2**($n.chars-1) +} -- cgit