aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-306/wambash/raku/ch-2.raku33
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-306/wambash/raku/ch-2.raku b/challenge-306/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..5c18ab6481
--- /dev/null
+++ b/challenge-306/wambash/raku/ch-2.raku
@@ -0,0 +1,33 @@
+#!/usr/bin/env raku
+use v6e.PREVIEW;
+
+sub max-rest (+@a) {
+ my ($ind,$max) = @a.max: :kv;
+ $max, @a.skip: $ind, 1
+}
+
+sub next-element (@ints) {
+ my ($max, $rest) = max-rest @ints;
+ my ($max2, $rest2) = max-rest $rest;
+
+ $max-$max2 || Empty, |$rest2
+}
+
+sub last-element (+ints) {
+ ints, &next-element ... *.elems ≤ 1
+ andthen .tail.head // 0
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply max-rest(1,2,3,2,1), (3,(1,2,2,1).Seq);
+ is-deeply max-rest(1,2,2,1), (2,(1,2,1).Seq);
+ is-deeply next-element((3, 8, 5, 2, 9, 2)), (1,3,5,2,2);
+ is-deeply last-element(3, 8, 5, 2, 9, 2),1;
+ is-deeply last-element(3, 2, 5),0;
+ done-testing;
+}
+
+multi MAIN (+ints) {
+ say last-element ints
+}