From c48f6fe33ea8b35ec2816fd0792b369ef5c073f6 Mon Sep 17 00:00:00 2001 From: Util Date: Sat, 29 Jun 2024 21:08:26 -0700 Subject: Add TWC 275 solutions by Bruce Gray, in Raku only. --- challenge-275/bruce-gray/raku/ch-1.raku | 18 ++++++++++++++++++ challenge-275/bruce-gray/raku/ch-2.raku | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 challenge-275/bruce-gray/raku/ch-1.raku create mode 100644 challenge-275/bruce-gray/raku/ch-2.raku 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 = + , + , + , + , +; +for @tests -> ( $in, $expected ) { + is task2($in), $expected; +} -- cgit