aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-06-30 13:49:39 +0100
committerGitHub <noreply@github.com>2024-06-30 13:49:39 +0100
commit6f401642435ccfb226356a1079f44ccdfc7cc00a (patch)
tree827e82820be043be6ad619925b148724c2bbe37d
parent2882b10624d6b3296283c66f50ea27baeab224ec (diff)
parentc48f6fe33ea8b35ec2816fd0792b369ef5c073f6 (diff)
downloadperlweeklychallenge-club-6f401642435ccfb226356a1079f44ccdfc7cc00a.tar.gz
perlweeklychallenge-club-6f401642435ccfb226356a1079f44ccdfc7cc00a.tar.bz2
perlweeklychallenge-club-6f401642435ccfb226356a1079f44ccdfc7cc00a.zip
Merge pull request #10340 from Util/c275
Add TWC 275 solutions by Bruce Gray, in Raku only.
-rw-r--r--challenge-275/bruce-gray/raku/ch-1.raku18
-rw-r--r--challenge-275/bruce-gray/raku/ch-2.raku19
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-275/bruce-gray/raku/ch-1.raku b/challenge-275/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..2131172a29
--- /dev/null
+++ b/challenge-275/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,18 @@
+sub task1 ( @broken_keys, Str $sentence --> UInt ) {
+ my @w = $sentence.lc.words;
+
+ my $bk = @broken_keys».lc.Set;
+
+ return +grep { !( .comb ∩ $bk ) }, @w;
+}
+
+
+use Test; plan +my @tests =
+ ( 0, 'la' , 'Perl Weekly Challenge' ),
+ ( 1, 'a' , 'Perl and Raku' ),
+ ( 2, 'lo' , 'Well done Team PWC' ),
+ ( 2, 'T' , 'The joys of polyglottism' ),
+;
+for @tests -> ( $expected, $in_keys, $in_sentence ) {
+ is task1($in_keys.comb, $in_sentence), $expected;
+}
diff --git a/challenge-275/bruce-gray/raku/ch-2.raku b/challenge-275/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..89fc2cc6aa
--- /dev/null
+++ b/challenge-275/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,19 @@
+sub task2 ( Str $s --> Str ) {
+ my $prior_char;
+
+ return [~] gather for $s.comb {
+ if /<.alpha>/ { take $prior_char = $_ }
+ else { take chr( $_ + $prior_char.ord ) }
+ }
+}
+
+
+use Test; plan +my @tests =
+ <a1c1e1 abcdef>,
+ <a1b2c3d4 abbdcfdh>,
+ <b2b bdb>,
+ <a16z abgz>,
+;
+for @tests -> ( $in, $expected ) {
+ is task2($in), $expected;
+}