aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-331/ash/raku/ch-1.raku10
-rw-r--r--challenge-331/ash/raku/ch-2.raku20
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-331/ash/raku/ch-1.raku b/challenge-331/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..1ed82f7896
--- /dev/null
+++ b/challenge-331/ash/raku/ch-1.raku
@@ -0,0 +1,10 @@
+# Task 1 of the Weekly Challenge 331
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-331/#TASK1
+
+say last-word-length('The Weekly Challenge'); # 9
+say last-word-length(' Hello World '); # 5
+say last-word-length('Let\'s begin the fun'); # 3
+
+sub last-word-length($str) {
+ $str.words[*-1].chars
+}
diff --git a/challenge-331/ash/raku/ch-2.raku b/challenge-331/ash/raku/ch-2.raku
new file mode 100644
index 0000000000..3a3287994d
--- /dev/null
+++ b/challenge-331/ash/raku/ch-2.raku
@@ -0,0 +1,20 @@
+# Task 2 of the Weekly Challenge 331
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-331/#TASK2
+
+say is-buddy-strings('fuck', 'fcuk'); # True
+say is-buddy-strings('love', 'love'); # False
+say is-buddy-strings('fodo', 'food'); # True
+say is-buddy-strings('feed', 'feed'); # True
+
+
+sub is-buddy-strings($str1, $str2) {
+ for 0..^$str1.chars - 1 -> $i {
+ return True if
+ $str2 eq $str1.substr(0, $i) ~
+ $str1.substr($i + 1, 1) ~
+ $str1.substr($i, 1) ~
+ $str1.substr($i + 2, $str1.chars - $i);
+ }
+
+ return False;
+}