diff options
| author | Util <bruce.gray@acm.org> | 2024-06-29 21:08:26 -0700 |
|---|---|---|
| committer | Util <bruce.gray@acm.org> | 2024-06-29 21:08:26 -0700 |
| commit | c48f6fe33ea8b35ec2816fd0792b369ef5c073f6 (patch) | |
| tree | 42b3423b359ab7bfd42db22d4ab0b7f2609b0f57 | |
| parent | 5fc0c6973b01bdad871f1d6edef5be929d8fe42e (diff) | |
| download | perlweeklychallenge-club-c48f6fe33ea8b35ec2816fd0792b369ef5c073f6.tar.gz perlweeklychallenge-club-c48f6fe33ea8b35ec2816fd0792b369ef5c073f6.tar.bz2 perlweeklychallenge-club-c48f6fe33ea8b35ec2816fd0792b369ef5c073f6.zip | |
Add TWC 275 solutions by Bruce Gray, in Raku only.
| -rw-r--r-- | challenge-275/bruce-gray/raku/ch-1.raku | 18 | ||||
| -rw-r--r-- | challenge-275/bruce-gray/raku/ch-2.raku | 19 |
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; +} |
