aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-01-23 00:55:30 +0000
committerGitHub <noreply@github.com>2023-01-23 00:55:30 +0000
commite5670fdc4ea9def34b31d09aae2b70d82a0a922c (patch)
tree41ba5cd3715f586c167784371aa5547db1267645
parente3e622b6d1519f744c7cffcfdad9a7a4d463fad3 (diff)
parentbf1836a77b54c40dab88d6a20c7efb110ac1dc8b (diff)
downloadperlweeklychallenge-club-e5670fdc4ea9def34b31d09aae2b70d82a0a922c.tar.gz
perlweeklychallenge-club-e5670fdc4ea9def34b31d09aae2b70d82a0a922c.tar.bz2
perlweeklychallenge-club-e5670fdc4ea9def34b31d09aae2b70d82a0a922c.zip
Merge pull request #7446 from wambash/challenge-week-200
solution week 200-1
-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
+}