aboutsummaryrefslogtreecommitdiff
path: root/challenge-196/sgreen/python
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-12-26 14:20:09 +0000
committerGitHub <noreply@github.com>2022-12-26 14:20:09 +0000
commitae146d8ac3d7fd8a856be32a4367693d574d914d (patch)
treedf39baa009d2f572ebc6a3d2d1f5cc0a953d60e7 /challenge-196/sgreen/python
parentdae0a10e23b470229e2440cd0683b3a90a1e4ca4 (diff)
parent63fb76188e132564e50feefd2d9d5b8491568948 (diff)
downloadperlweeklychallenge-club-ae146d8ac3d7fd8a856be32a4367693d574d914d.tar.gz
perlweeklychallenge-club-ae146d8ac3d7fd8a856be32a4367693d574d914d.tar.bz2
perlweeklychallenge-club-ae146d8ac3d7fd8a856be32a4367693d574d914d.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-196/sgreen/python')
-rwxr-xr-xchallenge-196/sgreen/python/ch-1.py20
-rwxr-xr-xchallenge-196/sgreen/python/ch-2.py31
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-196/sgreen/python/ch-1.py b/challenge-196/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..57b37a70da
--- /dev/null
+++ b/challenge-196/sgreen/python/ch-1.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+
+from itertools import combinations
+import sys
+
+def main(n):
+ # Work through all combinations of positions
+ for x in combinations(range(len(n)), 3):
+ i, j, k = sorted(x)
+ if n[i] < n[k] < n[j]:
+ print(f'({n[i]}, {n[j]}, {n[k]})')
+ return
+
+ # No solution is found
+ print('()')
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)
diff --git a/challenge-196/sgreen/python/ch-2.py b/challenge-196/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..ce0f95cd62
--- /dev/null
+++ b/challenge-196/sgreen/python/ch-2.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ solutions = []
+
+ # Go through the list until it is exhausted
+ while len(n):
+ start = end = n.pop(0)
+
+ # See if the next number is one more than the last value
+ while len(n) > 0 and n[0] == end+1:
+ end = n.pop(0)
+
+ # We have found a range
+ if start != end:
+ solutions.append(f'[{start},{end}]')
+
+ # Print solution
+ if solutions:
+ print(*solutions, sep=', ')
+ else:
+ print('No solutions found!')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)