diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-09-21 23:31:29 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-09-21 23:31:29 +0200 |
| commit | a4f5892fa08976e0b0a185819f6eaa845cbd50c0 (patch) | |
| tree | d4189581c49cd88fa540fef894837f9bd93d458e | |
| parent | b4d4e1fd9c324b67ff172c320de7a71b28d9e9e1 (diff) | |
| download | perlweeklychallenge-club-a4f5892fa08976e0b0a185819f6eaa845cbd50c0.tar.gz perlweeklychallenge-club-a4f5892fa08976e0b0a185819f6eaa845cbd50c0.tar.bz2 perlweeklychallenge-club-a4f5892fa08976e0b0a185819f6eaa845cbd50c0.zip | |
feat: add solution for challenge 339 from BarrOff
| -rw-r--r-- | challenge-339/barroff/raku/ch-2.p6 | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-339/barroff/raku/ch-2.p6 b/challenge-339/barroff/raku/ch-2.p6 new file mode 100644 index 0000000000..170bbe2beb --- /dev/null +++ b/challenge-339/barroff/raku/ch-2.p6 @@ -0,0 +1,30 @@ +#!/usr/bin/env raku + +use v6.d; + +sub peak-point(@gain --> Int) { + my Int $mg = 0; + my Int $current = 0; + for @gain -> $i { + $current += $i; + $mg = $current if $current > $mg; + } + return $mg; +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 5; + + is peak-point([-5, 1, 5, -9, 2]), 1, 'works for [-5, 1, 5, -9, 2]'; + is peak-point([10, 10, 10, -25]), 30, 'works for [10, 10, 10, -25]'; + is peak-point([3, -4, 2, 5, -6, 1]), 6, 'works for [3, -4, 2, 5, -6, 1]'; + is peak-point([-1, -2, -3, -4]), 0, 'works for [-1, -2, -3, -4]'; + is peak-point([-10, 15, 5]), 10, 'works for [-10, 15, 5]'; +} + +#| Take user provided numbers 5 9 3 4 6 +multi sub MAIN(*@gain) { + say peak-point(@gain); +} |
