diff options
| author | Andrew Shitov <mail@andreyshitov.com> | 2025-07-21 08:05:05 +0200 |
|---|---|---|
| committer | Andrew Shitov <mail@andreyshitov.com> | 2025-07-21 08:05:05 +0200 |
| commit | 547e4376468ee2f261dbeba7e3762b162fa2be25 (patch) | |
| tree | 8f64d1d5940312bec21fa53d0e69dfdad2c7f468 | |
| parent | e0f7e800fc8f1b2cb50896852a0a3ed61980f510 (diff) | |
| download | perlweeklychallenge-club-547e4376468ee2f261dbeba7e3762b162fa2be25.tar.gz perlweeklychallenge-club-547e4376468ee2f261dbeba7e3762b162fa2be25.tar.bz2 perlweeklychallenge-club-547e4376468ee2f261dbeba7e3762b162fa2be25.zip | |
Solutions Week 331 in Raku by @ash
| -rw-r--r-- | challenge-331/ash/raku/ch-1.raku | 10 | ||||
| -rw-r--r-- | challenge-331/ash/raku/ch-2.raku | 20 |
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; +} |
