aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2022-11-08 07:37:11 +0000
committerMark <53903062+andemark@users.noreply.github.com>2022-11-08 07:37:11 +0000
commitf4096abb2329c645192d43e30c0b8726c43189fa (patch)
treee08423b22f212aa6e01f597b9d7286e2726af9ce
parent1b25498f4abe3f5dba99bc8b1190263c14b87ffe (diff)
downloadperlweeklychallenge-club-f4096abb2329c645192d43e30c0b8726c43189fa.tar.gz
perlweeklychallenge-club-f4096abb2329c645192d43e30c0b8726c43189fa.tar.bz2
perlweeklychallenge-club-f4096abb2329c645192d43e30c0b8726c43189fa.zip
Challenge 190 do-over (Raku)
-rw-r--r--challenge-190/mark-anderson/raku/ch-1.raku2
-rw-r--r--challenge-190/mark-anderson/raku/ch-2.raku38
2 files changed, 23 insertions, 17 deletions
diff --git a/challenge-190/mark-anderson/raku/ch-1.raku b/challenge-190/mark-anderson/raku/ch-1.raku
index 16b5ff297a..00301d78f5 100644
--- a/challenge-190/mark-anderson/raku/ch-1.raku
+++ b/challenge-190/mark-anderson/raku/ch-1.raku
@@ -8,5 +8,5 @@ ok capital-detection("raku");
sub capital-detection($s)
{
- any($s eq $s.tclc, $s eq $s.lc, $s eq $s.uc)
+ $s eq any($s.tclc, $s.lc, $s.uc)
}
diff --git a/challenge-190/mark-anderson/raku/ch-2.raku b/challenge-190/mark-anderson/raku/ch-2.raku
index be1685915e..9f049c1bab 100644
--- a/challenge-190/mark-anderson/raku/ch-2.raku
+++ b/challenge-190/mark-anderson/raku/ch-2.raku
@@ -1,24 +1,30 @@
#!/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 >;
+is-deeply decoded-list(11), < AA K >;
+is-deeply decoded-list(1115), < AAAE AAO AKE KAE KO >;
+is-deeply decoded-list(127), < ABG LG >;
+is-deeply decoded-list(1002005), < ABE JBE JTE >;
-# Not sure how to deal with zeros but this is what the program does.
-is-deeply decode-counts(1002001), < ABA ATA JBA JTA >;
+sub decoded-list($n is copy)
+{
+ $n ~~ s:g/0+/0/; # Ignoring leading zeros to make things easy.
+
+ ones-and-twos($n.chars).map({ $n.comb.rotor($_)>>.join>>.Int })
+ .grep({ all($_) ~~ 1..26 })
+ .deepmap({ chr($_ + 64) })
+ .map({ .join });
+}
-sub decode-counts($n)
+sub ones-and-twos($n)
{
- sub composition($_)
- {
- gather .fmt('%0' ~ $n.chars ~ 'b') ~~ m:g/(.)$0* <?{ take $/.pos - $/.from }>/
- }
+ my $start = ((0,0,1) xx *).flat.head($n).join.parse-base(2);
+ my $stop = ((0,1,1) xx *).flat.head($n).join.parse-base(2);
- sort map
- {
- my $c := $n.comb.rotor(composition($_))>>.join>>.Int;
- next unless all($c) ~~ 1..26;
- [~] $c.map({ chr($_+64) });
- }, ^2**($n.chars-1)
+ sort map
+ {
+ my $b = .fmt('%0' ~ $n ~ 'b');
+ next if $b ~~ /000|111/;
+ gather $b ~~ m:g/(.)$0? <?{ take $/.pos - $/.from }>/
+ }, $start..$stop
}