aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-11-09 20:05:21 +0000
committerGitHub <noreply@github.com>2022-11-09 20:05:21 +0000
commitf57d942dc09a7ccc3cad8ccf4c0507aaae5aecd2 (patch)
tree41589c1bf7fe1fd42a6bcf47c0b3890f310b8d97
parent22c953f7e5bb9068e35b16aaa58e71b0ae592d64 (diff)
parent87997719ba499f2b60ab4307bb4b56a5a4eb9f00 (diff)
downloadperlweeklychallenge-club-f57d942dc09a7ccc3cad8ccf4c0507aaae5aecd2.tar.gz
perlweeklychallenge-club-f57d942dc09a7ccc3cad8ccf4c0507aaae5aecd2.tar.bz2
perlweeklychallenge-club-f57d942dc09a7ccc3cad8ccf4c0507aaae5aecd2.zip
Merge pull request #7057 from massa/massa/challenge190
decode-counts gave me some trouble
-rw-r--r--challenge-190/massa/raku/ch-1.raku31
-rw-r--r--challenge-190/massa/raku/ch-2.raku39
2 files changed, 70 insertions, 0 deletions
diff --git a/challenge-190/massa/raku/ch-1.raku b/challenge-190/massa/raku/ch-1.raku
new file mode 100644
index 0000000000..1de5f81ce8
--- /dev/null
+++ b/challenge-190/massa/raku/ch-1.raku
@@ -0,0 +1,31 @@
+
+#!/usr/bin/env raku
+
+=begin pod
+
+Week 190:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-190
+
+Task #1: Capital Detection
+
+ Write a script to find out if the usage of Capital is appropriate if it satisfies at least one of the following rules:
+
+ 1) Only first letter is capital and all others are small.
+ 2) Every letter is small.
+ 3) Every letter is capital.
+
+=end pod
+
+use Test;
+
+my regex capital-detection { ^ [ <upper> <lower>* | <upper>+ | <lower>+ ] $ }
+
+ok 'Perl' ~~ /<capital-detection>/;
+ok 'TPF' ~~ /<capital-detection>/;
+nok 'PyThon' ~~ /<capital-detection>/;
+ok 'raku' ~~ /<capital-detection>/;
+
+done-testing;
+
+
diff --git a/challenge-190/massa/raku/ch-2.raku b/challenge-190/massa/raku/ch-2.raku
new file mode 100644
index 0000000000..f59da3aef9
--- /dev/null
+++ b/challenge-190/massa/raku/ch-2.raku
@@ -0,0 +1,39 @@
+
+#!/usr/bin/env raku
+
+=begin pod
+
+Week 190:
+
+ https://theweeklychallenge.org/blog/perl-weekly-challenge-190
+
+Task #2: Decoded List
+
+ You are given an encoded string consisting of a sequence of numeric
+ characters: C<0..9>, C<$s>.
+
+ Write a script to find the all valid different decodings in sorted order.
+
+ Encoding is simply done by mapping A,B,C,D,… to 1,2,3,4,… etc.
+
+
+=end pod
+
+use Test;
+
+is-deeply <AA K>, decoded-list 11;
+is-deeply <AAAE AAO AKE KAE KO>, decoded-list 1115;
+is-deeply <ABG LG>, decoded-list 127;
+
+done-testing;
+
+sub decoded-list(Str() $_) {
+ combinations(.chars + 1, .chars div 2 .. .chars + 1)».\ # all the combinations
+ rotor(2=>-1)».Array».map({.[0] ..^ .[1]})».Array.\ # transformed in contiguous subsets
+ grep(*».elems.all == 1|2).\ # subsets must be of size one or two
+ grep(*».elems.sum == .chars)».\ # and they must cover the whole string
+ map(-> @s { .comb[@s].join })».\ # map to the original string's chars
+ trans([1..26] => ['A'..'Z'])».join.\ # decode
+ sort.unique
+}
+