aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-11-02 19:33:29 +0000
committerGitHub <noreply@github.com>2025-11-02 19:33:29 +0000
commitc216d7363a89eeb322f1bd48ae535c3d394f39e2 (patch)
treefffc2fa8b7a6a0b85eba2f39c9f44e9c854b6b8e
parenta5d2acad3d6f5b2e9e874d889f800878db24251d (diff)
parent5834bc8959583d6d7f3c31001916abffef9afecb (diff)
downloadperlweeklychallenge-club-c216d7363a89eeb322f1bd48ae535c3d394f39e2.tar.gz
perlweeklychallenge-club-c216d7363a89eeb322f1bd48ae535c3d394f39e2.tar.bz2
perlweeklychallenge-club-c216d7363a89eeb322f1bd48ae535c3d394f39e2.zip
Merge pull request #12960 from oWnOIzRi/week345
add solution week345 task 1 in python
-rw-r--r--challenge-345/steven-wilson/python/ch_1.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-345/steven-wilson/python/ch_1.py b/challenge-345/steven-wilson/python/ch_1.py
new file mode 100644
index 0000000000..a07ed939a9
--- /dev/null
+++ b/challenge-345/steven-wilson/python/ch_1.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+
+def peak_position(ints):
+ """ Given an array of integers, find all the peaks in the array, a peak is
+ an element that is strictly greater than its left and right neighbours.
+ Return the indices of all such peak positions.
+ >>> peak_position([1, 3, 2])
+ [1]
+ >>> peak_position([2, 4, 6, 5, 3])
+ [2]
+ >>> peak_position([1, 2, 3, 2, 4, 1])
+ [2, 4]
+ >>> peak_position([5, 3, 1])
+ []
+ >>> peak_position([1, 5, 1, 5, 1, 5, 1])
+ [1, 3, 5]
+ """
+ return [n for n, i in enumerate(ints) if n > 0 and n < len(ints) - 1
+ and i > ints[n-1] and i > ints[n + 1]]
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod(verbose=True)