aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-200/wambash/raku/ch-1.raku29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-200/wambash/raku/ch-1.raku b/challenge-200/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..e7901231c1
--- /dev/null
+++ b/challenge-200/wambash/raku/ch-1.raku
@@ -0,0 +1,29 @@
+#!/usr/bin/env raku
+use v6.e.PREVIEW;
+
+sub is-arithmetic-slice (+@list) {
+ @list
+ #andthen .snitch
+ andthen .rotor: 2 => -1
+ andthen .map: -> ($a,$b) { $b - $a }\
+ andthen [==] $_
+}
+
+sub arithmetic-slices (+@list) {
+ @list
+ andthen m:s:ex/(\d+) **? 3..* <?{ is-arithmetic-slice $/.[0] }>/
+ andthen .map: *.[0]ยป.Int
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is-deeply arithmetic-slices(1,2,3,4),([1,2,3],[1,2,3,4],[2,3,4]);
+ is-deeply arithmetic-slices(2),();
+ is-deeply arithmetic-slices(1,2,3,5,7),([1,2,3],[3,5,7]);
+ is-deeply arithmetic-slices(1,2,3,5,7,10,14,19,29,39),([1,2,3],[3,5,7],[19,29,39]);
+ done-testing;
+}
+
+multi MAIN (+@list) {
+ say arithmetic-slices +@list
+}