aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-325/wambash/raku/ch-1.raku22
-rw-r--r--challenge-325/wambash/raku/ch-2.raku21
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-325/wambash/raku/ch-1.raku b/challenge-325/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..2c1b0a2141
--- /dev/null
+++ b/challenge-325/wambash/raku/ch-1.raku
@@ -0,0 +1,22 @@
+#!/usr/bin/env raku
+
+multi consecutive-one-producer ($acc,0 --> 0) {}
+multi consecutive-one-producer ($acc,1 --> Int:D) {$acc + 1}
+
+sub consecutive-one (+binary) {
+ binary
+ andthen .produce: &consecutive-one-producer
+ andthen .max
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is consecutive-one(0,1,1,0,1,1,1), 3;
+ is consecutive-one(0 xx 4), 0;
+ is consecutive-one(1,0,1,0,1,1), 2;
+ done-testing;
+}
+
+multi MAIN (+binary) {
+ say consecutive-one binary;
+}
diff --git a/challenge-325/wambash/raku/ch-2.raku b/challenge-325/wambash/raku/ch-2.raku
new file mode 100644
index 0000000000..4d6c1e63ce
--- /dev/null
+++ b/challenge-325/wambash/raku/ch-2.raku
@@ -0,0 +1,21 @@
+#!/usr/bin/env raku
+
+sub final-price (+prices) {
+ |prices, 0
+ andthen $_, *.skip ...^ *.elems == 1
+ andthen .map: -> @ ($h, *@t) {
+ $h - @t.first: { $_ ≤ $h }
+ }
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is final-price(8, 4, 6, 2, 3), (4,2,4,2,3);
+ is final-price(1..5), 1..5;
+ is final-price(7,1,1,5), (6,0,1,5);
+ done-testing;
+}
+
+multi MAIN (+prices) {
+ put final-price prices;
+}