aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-115/stuart-little/raku/ch-1.p615
-rwxr-xr-xchallenge-115/stuart-little/raku/ch-2.p68
2 files changed, 23 insertions, 0 deletions
diff --git a/challenge-115/stuart-little/raku/ch-1.p6 b/challenge-115/stuart-little/raku/ch-1.p6
new file mode 100755
index 0000000000..5a5044ab4e
--- /dev/null
+++ b/challenge-115/stuart-little/raku/ch-1.p6
@@ -0,0 +1,15 @@
+#!/usr/bin/env perl6
+use v6;
+
+# run <script> <space-separated strings>
+
+sub canChain(@words,$start,$end) {
+ (! @words.elems) && return 0;
+ @words.elems == 1 && do {
+ return (@words[0].substr(0,1) eq $start && @words[0].substr(*-1) eq $end).Int;
+ };
+ my @startIdxs = @words.keys.grep({ @words[$_].substr(0,1) eq $start });
+ return @startIdxs.map({ canChain(@words[(@words.keys (-) $_).keys.sort], substr(@words[$_],*-1), $end) }).any.Bool.Int;
+}
+
+((@*ARGS.elems < 2) ?? (0) !! (canChain(@*ARGS[1..*],substr(@*ARGS[0],*-1),substr(@*ARGS[0],0,1)))).say;
diff --git a/challenge-115/stuart-little/raku/ch-2.p6 b/challenge-115/stuart-little/raku/ch-2.p6
new file mode 100755
index 0000000000..f563f38fc7
--- /dev/null
+++ b/challenge-115/stuart-little/raku/ch-2.p6
@@ -0,0 +1,8 @@
+#!/usr/bin/env perl6
+use v6;
+
+# run <script> <space-separated digits>
+
+my $attemptedOut = S/(.)(<[13579]>*)$/$1$0/ with @*ARGS.sort({ $^b leg $^a }).join("");
+say(($attemptedOut ~~ m/<[02468]>$/) ?? ($attemptedOut) !! ("No even digits.."));
+