diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-08-17 23:49:23 +0200 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-08-17 23:49:23 +0200 |
| commit | cf91edfd0717752825913caea01c6e0cdccac300 (patch) | |
| tree | bd2bbe7dbf9fee1dc2e5bbdc5479032c3fbb7ca3 | |
| parent | 36cc6a3f6b5b5d7f3e7c072a251435352c998dd2 (diff) | |
| download | perlweeklychallenge-club-cf91edfd0717752825913caea01c6e0cdccac300.tar.gz perlweeklychallenge-club-cf91edfd0717752825913caea01c6e0cdccac300.tar.bz2 perlweeklychallenge-club-cf91edfd0717752825913caea01c6e0cdccac300.zip | |
feat: add solution for challenge 334 from BarrOff
| -rw-r--r-- | challenge-334/barroff/raku/ch-1.p6 | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-334/barroff/raku/ch-1.p6 b/challenge-334/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..a21aaa27e0 --- /dev/null +++ b/challenge-334/barroff/raku/ch-1.p6 @@ -0,0 +1,27 @@ +#!/usr/bin/env raku + +use v6.d; + +sub range-sum(Int $x, Int $y, @ints --> Int) { + sum(@ints[$x..$y]); +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 5; + + is range-sum(0, 2, [-2, 0, 3, -5, 2, -1]), 1, + 'works for "[-2, 0, 3, -5, 2, -1]"'; + is range-sum(1, 3, [1, -2, 3, -4, 5]), -3, 'works for "[1, -2, 3, -4, 5]"'; + is range-sum(3, 4, [1, 0, 2, -1, 3]), 2, 'works for "[1, 0, 2, -1, 3]"'; + is range-sum(0, 3, [-5, 4, -3, 2, -1, 0]), -2, + 'works for "[-5, 4, -3, 2, -1, 0]"'; + is range-sum(0, 2, [-1, 0, 2, -3, -2, 1]), 1, + 'works for "[-1, 0, 2, -3, -2, 1]"'; +} + +#| Take user provided numbers like 0 2 -2 0 3 -5 2 -1 +multi sub MAIN(Int $x, Int $y, *@ints) { + say range-sum($x, $y, @ints); +} |
