aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-09-24 00:31:14 +0100
committerGitHub <noreply@github.com>2025-09-24 00:31:14 +0100
commit357ac44143ecf984f0dcddda40e86b17175c351c (patch)
tree22f42027a0e98c74737d9046b24353fb1b740ed9
parent49a0e0792e0a1ebde4d43254c5158b682c9aa606 (diff)
parenta4f5892fa08976e0b0a185819f6eaa845cbd50c0 (diff)
downloadperlweeklychallenge-club-357ac44143ecf984f0dcddda40e86b17175c351c.tar.gz
perlweeklychallenge-club-357ac44143ecf984f0dcddda40e86b17175c351c.tar.bz2
perlweeklychallenge-club-357ac44143ecf984f0dcddda40e86b17175c351c.zip
Merge pull request #12732 from BarrOff/barroff-339
feat: add solution for challenge 339 from BarrOff
-rw-r--r--challenge-339/barroff/raku/ch-2.p630
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);
+}