diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-06-12 13:45:44 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-12 13:45:44 +0100 |
| commit | dbcca4b9906de55925c588a3d16889aa3f697a8f (patch) | |
| tree | 8ad0e8e0ecf78ff7a00a9ffe1d5c97af8c1934c7 | |
| parent | fef6253897be4d34e281518173f5ad316297d03c (diff) | |
| parent | 0d26018c85d161b99772e1a0dcf1ea846271e577 (diff) | |
| download | perlweeklychallenge-club-dbcca4b9906de55925c588a3d16889aa3f697a8f.tar.gz perlweeklychallenge-club-dbcca4b9906de55925c588a3d16889aa3f697a8f.tar.bz2 perlweeklychallenge-club-dbcca4b9906de55925c588a3d16889aa3f697a8f.zip | |
Merge pull request #12169 from wambash/challenge-week-325
solutions week 325
| -rw-r--r-- | challenge-325/wambash/raku/ch-1.raku | 22 | ||||
| -rw-r--r-- | challenge-325/wambash/raku/ch-2.raku | 21 |
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; +} |
