aboutsummaryrefslogtreecommitdiff
path: root/challenge-200/sgreen/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-200/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-200/sgreen/python/ch-1.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-200/sgreen/python/ch-1.py b/challenge-200/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..0d65c06fad
--- /dev/null
+++ b/challenge-200/sgreen/python/ch-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ solutions = []
+
+ for start in range(len(n)-2):
+ # Calculate the difference between the first two values
+ diff = abs(n[start] - n[start+1])
+
+ for end in range(start+2, len(n)):
+ if abs(n[end] - n[end-1]) == diff:
+ # We have a solution
+ solutions.append(tuple(n[start:end+1]))
+ else:
+ break
+
+ if solutions:
+ print(*solutions, sep=', ')
+ else:
+ print('()')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)