diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-11-02 23:21:57 +0100 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2025-11-02 23:21:57 +0100 |
| commit | 0dee9f98d61963e464d0af7259226b44ba22a32a (patch) | |
| tree | 82b94ba1064dae13d26489e9343eece751ec060d | |
| parent | c216d7363a89eeb322f1bd48ae535c3d394f39e2 (diff) | |
| download | perlweeklychallenge-club-0dee9f98d61963e464d0af7259226b44ba22a32a.tar.gz perlweeklychallenge-club-0dee9f98d61963e464d0af7259226b44ba22a32a.tar.bz2 perlweeklychallenge-club-0dee9f98d61963e464d0af7259226b44ba22a32a.zip | |
feat: add solution for challenge 345 from BarrOff
| -rw-r--r-- | challenge-345/barroff/raku/ch-1.p6 | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-345/barroff/raku/ch-1.p6 b/challenge-345/barroff/raku/ch-1.p6 new file mode 100644 index 0000000000..abd864f45f --- /dev/null +++ b/challenge-345/barroff/raku/ch-1.p6 @@ -0,0 +1,31 @@ +#!/usr/bin/env raku + +use v6.d; + +sub peak-positions(@ints --> Array:D) { + my @prep = @ints[0] > @ints[1] ?? (0) !! (); + my @appe = @ints[*-1] > @ints[*-2] ?? (@ints.elems - 1) !! (); + my @result = grep( + { @ints[$_] > @ints[$_ - 1] and @ints[$_] > @ints[$_ + 1] }, + 1..@ints.elems - 2 + ); + @result.prepend(@prep).append(@appe); +} + +#| Run test cases +multi sub MAIN('test') { + use Test; + plan 5; + + is peak-positions([1, 3, 2]), (1), 'works for [1, 3, 2]'; + is peak-positions([2, 4, 6, 5, 3]), (2), 'works for [2, 4, 6, 5, 3]'; + is peak-positions([1, 2, 3, 2, 4, 1]), (2, 4), 'works for [1, 2, 3, 2, 4, 1]'; + is peak-positions([5, 3, 1]), (0), 'works for [5, 3, 1]'; + is peak-positions([1, 5, 1, 5, 1, 5, 1]), (1, 3, 5), + 'works for [1, 5, 1, 5, 1, 5, 1]'; +} + +#| Take user provided numbers 5 9 3 4 6 +multi sub MAIN(*@ints) { + say peak-positions(@ints); +} |
