aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-341/ash/raku/ch-1.raku18
-rw-r--r--challenge-341/ash/raku/ch-2.raku14
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-341/ash/raku/ch-1.raku b/challenge-341/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..ccd63a5848
--- /dev/null
+++ b/challenge-341/ash/raku/ch-1.raku
@@ -0,0 +1,18 @@
+# Task 1 of the Weekly Challenge 341
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-341/#TASK1
+
+say count-words('Hello World', ['d']); # 1
+say count-words('apple banana cherry', ['a', 'e']); # 0
+say count-words('Coding is fun', []); # 3
+say count-words('The Weekly Challenge', ['a','b']); # 2
+say count-words('Perl and Python', ['p']); # 1
+
+sub count-words($string, @broken-keys) {
+ my @words = $string.lc.words;
+ my $possible-words = @words.elems;
+ for @words -> $word {
+ $possible-words-- if $word.comb (&) @broken-keys;
+ }
+
+ return $possible-words;
+}
diff --git a/challenge-341/ash/raku/ch-2.raku b/challenge-341/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..1375a3ec4d
--- /dev/null
+++ b/challenge-341/ash/raku/ch-2.raku
@@ -0,0 +1,14 @@
+# Task 2 of the Weekly Challenge 341
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-341/#TASK2
+
+say reverse-prefix('programming', 'g'); # gorpramming
+say reverse-prefix('hello', 'h'); # hello
+say reverse-prefix('abcdefghij', 'h'); # hgfedcbaij
+say reverse-prefix('reverse', 's'); # srevere
+say reverse-prefix('perl', 'r'); # repl
+
+sub reverse-prefix($word, $char) {
+ $word ~~ /^ (.*? $char) (.*) $/;
+
+ return $/[0].flip ~ $/[1];
+}