diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-18 00:04:14 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-18 00:04:14 +0100 |
| commit | 1065e85061de1d09aba61d6bc102a3a94fe95ab7 (patch) | |
| tree | 297437654b35befa29f7975df6e7f46f049700b1 | |
| parent | 6366813d61f7b7ac8f0fb7a0bf5f384aa74a2d61 (diff) | |
| parent | cf91edfd0717752825913caea01c6e0cdccac300 (diff) | |
| download | perlweeklychallenge-club-1065e85061de1d09aba61d6bc102a3a94fe95ab7.tar.gz perlweeklychallenge-club-1065e85061de1d09aba61d6bc102a3a94fe95ab7.tar.bz2 perlweeklychallenge-club-1065e85061de1d09aba61d6bc102a3a94fe95ab7.zip | |
Merge pull request #12528 from BarrOff/barroff-334
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); +} |
