aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-07-22 00:17:38 +0100
committerGitHub <noreply@github.com>2025-07-22 00:17:38 +0100
commitd078752e52301993b10dbb5fff0da493897ce9af (patch)
tree8f64d1d5940312bec21fa53d0e69dfdad2c7f468
parente0f7e800fc8f1b2cb50896852a0a3ed61980f510 (diff)
parent547e4376468ee2f261dbeba7e3762b162fa2be25 (diff)
downloadperlweeklychallenge-club-d078752e52301993b10dbb5fff0da493897ce9af.tar.gz
perlweeklychallenge-club-d078752e52301993b10dbb5fff0da493897ce9af.tar.bz2
perlweeklychallenge-club-d078752e52301993b10dbb5fff0da493897ce9af.zip
Merge pull request #12378 from ash/ash-331
Solutions Week 331 in Raku by @ash
-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;
+}