aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-11-03 01:28:38 +0000
committerGitHub <noreply@github.com>2025-11-03 01:28:38 +0000
commiteccc8c75f60fa3e980d17cd415f9e982e501ecc3 (patch)
tree6fcb458da77481307da146c13e90e2de710965fe
parente9e269d92c6f5a51234e01cc7398da29564f872f (diff)
parent0dee9f98d61963e464d0af7259226b44ba22a32a (diff)
downloadperlweeklychallenge-club-eccc8c75f60fa3e980d17cd415f9e982e501ecc3.tar.gz
perlweeklychallenge-club-eccc8c75f60fa3e980d17cd415f9e982e501ecc3.tar.bz2
perlweeklychallenge-club-eccc8c75f60fa3e980d17cd415f9e982e501ecc3.zip
Merge pull request #12962 from BarrOff/barroff-345
feat: add solution for challenge 345 from BarrOff
-rw-r--r--challenge-345/barroff/raku/ch-1.p631
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);
+}