aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Krňávek <Jan.Krnavek@gmail.com>2025-10-05 14:23:23 +0200
committerJan Krňávek <Jan.Krnavek@gmail.com>2025-10-05 14:23:23 +0200
commitfb3e96d1cee930f319b787049d1130a6bf8e44d1 (patch)
tree323560e818cbe3cb7aa37fcf17b82f63fa3cc8ef
parent9506417ade8b33371ed335c95719c3ad5bf83c33 (diff)
downloadperlweeklychallenge-club-fb3e96d1cee930f319b787049d1130a6bf8e44d1.tar.gz
perlweeklychallenge-club-fb3e96d1cee930f319b787049d1130a6bf8e44d1.tar.bz2
perlweeklychallenge-club-fb3e96d1cee930f319b787049d1130a6bf8e44d1.zip
solutions week 341
-rw-r--r--challenge-341/wambash/raku/ch-1.raku23
-rw-r--r--challenge-341/wambash/raku/ch-2.raku22
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-341/wambash/raku/ch-1.raku b/challenge-341/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..c0f23228c7
--- /dev/null
+++ b/challenge-341/wambash/raku/ch-1.raku
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+sub broken-keyboard ($str, :$keys=()) {
+ $str
+ andthen .words
+ andthen .grep: { !.contains: $keys.any,:i }\
+ andthen .elems
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is broken-keyboard('Hello World', :keys<d> ), 1;
+ is broken-keyboard('apple banana cherry', :keys<a e> ), 0;
+ is broken-keyboard('Coding is fun', :keys() ), 3;
+ is broken-keyboard('Coding is fun' ), 3;
+ is broken-keyboard('The weekly challenge',:keys<a b> ), 2;
+ is broken-keyboard('Perl and Python',:keys<p> ), 1;
+ done-testing;
+}
+
+multi MAIN (+$str, :@keys) {
+ say broken-keyboard ~$str, :@keys;
+}
diff --git a/challenge-341/wambash/raku/ch-2.raku b/challenge-341/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..fe2623a99c
--- /dev/null
+++ b/challenge-341/wambash/raku/ch-2.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+
+sub reverse-prefix (+$str, :$char) {
+ my ($prefix, $root) = $str.split: / <?after "$char"> /, 2;
+
+ $prefix.flip ~ $root
+
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is reverse-prefix('perl',:char<r>), 'repl';
+ is reverse-prefix('programming',:char<g>), 'gorpramming';
+ is reverse-prefix('hello',:char<h>), 'hello';
+ is reverse-prefix('abcdefghij',:char<h>), 'hgfedcbaij';
+ is reverse-prefix('reverse',:char<s>), 'srevere';
+ done-testing;
+}
+
+multi MAIN (+$str, :$char) {
+ say reverse-prefix $str, :$char;
+}