aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUtil <bruce.gray@acm.org>2024-07-28 13:16:02 -0500
committerUtil <bruce.gray@acm.org>2024-07-28 13:16:02 -0500
commitff820358033cae32d68b6e1f7cade0c7302a2f2b (patch)
tree4d913b159141c5a6e0f6881d5c7137d37b8ff125
parentb18960b385431c5cf0b0b10dad1ece23b79fe623 (diff)
downloadperlweeklychallenge-club-ff820358033cae32d68b6e1f7cade0c7302a2f2b.tar.gz
perlweeklychallenge-club-ff820358033cae32d68b6e1f7cade0c7302a2f2b.tar.bz2
perlweeklychallenge-club-ff820358033cae32d68b6e1f7cade0c7302a2f2b.zip
Add TWC 279 solutions by Bruce Gray, in Raku only.
-rw-r--r--challenge-279/bruce-gray/raku/ch-1.raku18
-rw-r--r--challenge-279/bruce-gray/raku/ch-2.raku16
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-279/bruce-gray/raku/ch-1.raku b/challenge-279/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..3f764371e4
--- /dev/null
+++ b/challenge-279/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,18 @@
+sub task1 ( @letters, @weights --> Str ) {
+
+ warn "Ambiguous" if @weights.repeated;
+ warn "Unexpected" if @weights.sort !eqv (@weights.keys X+ 1);
+ warn "@letters is not the same size as @weights, but should be." if @letters !== @weights;
+
+ return ( @weights Z @letters ).sort».[1].join;
+}
+
+
+use Test; plan +constant @tests =
+ ( 'PERL' , <R E P L> , +«<3 2 1 4> ),
+ ( 'RAKU' , <A U R K> , +«<2 4 1 3> ),
+ ( 'PYTHON' , <O H Y N P T> , +«<5 4 2 6 1 3> ),
+;
+for @tests -> ( $expected, @letters, @weights ) {
+ is task1(@letters, @weights), $expected, "@letters[], @weights[]";
+}
diff --git a/challenge-279/bruce-gray/raku/ch-2.raku b/challenge-279/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..99c07426de
--- /dev/null
+++ b/challenge-279/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,16 @@
+sub task2 ( Str $s --> Bool ) {
+
+ my $vowel_count = $s.comb(/:i<[aeiou]>/).elems;
+
+ return $vowel_count %% 2;
+}
+
+
+use Test; plan +constant @tests =
+ ( False , 'perl' ),
+ ( True , 'book' ),
+ ( True , 'good morning' ),
+;
+for @tests -> ( $expected, $in ) {
+ is task2($in), $expected, $in;
+}