aboutsummaryrefslogtreecommitdiff
path: root/challenge-202/sgreen/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-202/sgreen/python')
-rwxr-xr-xchallenge-202/sgreen/python/ch-1.py28
-rwxr-xr-xchallenge-202/sgreen/python/ch-2.py32
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-202/sgreen/python/ch-1.py b/challenge-202/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..974ab31d78
--- /dev/null
+++ b/challenge-202/sgreen/python/ch-1.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ # Count the number of sequential odd numbers
+ odds = 0
+
+ for i in n:
+ if i % 2 == 1:
+ odds += 1
+ if odds >= 3:
+ # We have found three sequential odd numbers
+ print('1')
+ return
+ else:
+ # Restart the count
+ odds = 0
+
+ # There is no solution
+ print('0')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-202/sgreen/python/ch-2.py b/challenge-202/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..a17bd47631
--- /dev/null
+++ b/challenge-202/sgreen/python/ch-2.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ # This stores the current widest (leftmost) valley
+ solution = []
+
+ for valley in range(len(n)):
+ start = end = valley
+
+ # Get the values to the left that are >= the previous value
+ while start > 0 and n[start] <= n[start-1]:
+ start -= 1
+
+ # Get the values to the right that are >= the previous value
+ while end < len(n)-1 and n[end] <= n[end+1]:
+ end += 1
+
+ # If the len of this solution is larger than the previous, it's a
+ # better solution
+ if len(solution) < end-start:
+ solution = n[start:end+1]
+
+ print(*solution, sep=', ')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)