aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScimon <simon.proctor@gmail.com>2025-07-21 10:31:58 +0100
committerScimon <simon.proctor@gmail.com>2025-07-21 10:31:58 +0100
commit8de87d7dfeb2e14a175ef27a06533ee2db3418fe (patch)
treea9d792f182c36036b2760c71fe85cfdfebfecbb4
parente0f7e800fc8f1b2cb50896852a0a3ed61980f510 (diff)
downloadperlweeklychallenge-club-8de87d7dfeb2e14a175ef27a06533ee2db3418fe.tar.gz
perlweeklychallenge-club-8de87d7dfeb2e14a175ef27a06533ee2db3418fe.tar.bz2
perlweeklychallenge-club-8de87d7dfeb2e14a175ef27a06533ee2db3418fe.zip
Challenge 331. Have a nice holiday :)
-rwxr-xr-xchallenge-331/simon-proctor/raku/ch-1.raku31
-rwxr-xr-xchallenge-331/simon-proctor/raku/ch-2.raku46
2 files changed, 77 insertions, 0 deletions
diff --git a/challenge-331/simon-proctor/raku/ch-1.raku b/challenge-331/simon-proctor/raku/ch-1.raku
new file mode 100755
index 0000000000..4e49425202
--- /dev/null
+++ b/challenge-331/simon-proctor/raku/ch-1.raku
@@ -0,0 +1,31 @@
+#!/usr/bin/env raku
+
+multi sub MAIN(:t(:$test) where ?* ) is hidden-from-USAGE {
+ use Test;
+ is last-word("The Weekly Challenge"),9;
+ is last-word(" Hello World "),5;
+ is last-word("Let's begin the fun"),3;
+ is last-word(""),0;
+ is last-word(" "),0;
+ done-testing;
+}
+
+#|(Given a string find the length of the last word in it)
+multi sub MAIN(
+ Str $s #= A string made of one or more words
+) {
+ say last-word($s);
+}
+
+#|(Joins the arguments with spaces and gives the length of the last word)
+multi sub MAIN(
+ *@s where ?@s #= A string made of one or more words
+) {
+ say last-word(@s.join(" "));
+}
+
+subset Blank of Str where m/^ \s* $/;
+
+multi sub last-word(Blank $) { 0 }
+multi sub last-word(Str $s) { $s.comb(/\S+/)[*-1].codes }
+
diff --git a/challenge-331/simon-proctor/raku/ch-2.raku b/challenge-331/simon-proctor/raku/ch-2.raku
new file mode 100755
index 0000000000..e34a3f4c8c
--- /dev/null
+++ b/challenge-331/simon-proctor/raku/ch-2.raku
@@ -0,0 +1,46 @@
+#!/usr/bin/env raku
+
+multi sub infix:<buds> (Str() $source,
+ Str() $target where $target.codes != $source.codes) {
+ return False
+}
+multi sub infix:<buds> (Str() $source,
+ Str() $target where $target.codes <= 1) {
+ return False
+}
+multi sub infix:<buds> (Str() $source, Str() $target) {
+ my @target = $target.comb.Array;
+ my @check = $source.comb.Array;
+ for 0..^$target.codes -> $first {
+ for $first+1..^$target.codes -> $second {
+ @check[$first,$second] = @check[$second,$first];
+ return True if @check ~~ @target;
+ @check[$first,$second] = @check[$second,$first];
+ }
+ }
+ return False;
+}
+
+multi sub MAIN(:t(:$test) where ?* ) is hidden-from-USAGE {
+ use Test;
+ ok !("123" buds "1"), "Different Lengths";
+ ok !("1" buds "2"), "Too Short";
+ ok "fcuk" buds "fuck", "Exmaple 1";
+ ok "eovl" buds "love", "Swap anything";
+ ok !("love" buds "love"), "Example 2";
+ ok "fodo" buds "food", "Example 3";
+ ok "feed" buds "feed", "Example 4";
+ done-testing;
+}
+
+#|(Given two strings prints if they are buddy strings
+or not. They are buddy string if swapping two
+letters makes them the same.)
+multi sub MAIN(
+ Str $source #= Source string
+ ,Str $target #= Target string
+) {
+ say $source buds $target;
+}
+
+