From a4f5892fa08976e0b0a185819f6eaa845cbd50c0 Mon Sep 17 00:00:00 2001 From: BarrOff <58253563+BarrOff@users.noreply.github.com> Date: Sun, 21 Sep 2025 23:31:29 +0200 Subject: feat: add solution for challenge 339 from BarrOff --- challenge-339/barroff/raku/ch-2.p6 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 challenge-339/barroff/raku/ch-2.p6 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); +} -- cgit