aboutsummaryrefslogtreecommitdiff
path: root/challenge-208/sgreen/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-208/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-208/sgreen/python/ch-2.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-208/sgreen/python/ch-2.py b/challenge-208/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..84952f60f1
--- /dev/null
+++ b/challenge-208/sgreen/python/ch-2.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(array):
+ missing = None
+ duplicate = None
+
+ for i in range(1, len(array)+1):
+ # Find out how many times this number appears in the list
+ count = sum(1 for n in array if n == i)
+ if count == 0:
+ missing = i
+ elif count > 1:
+ duplicate = i
+
+ if missing is None:
+ print(-1)
+ else:
+ print(f'({duplicate or ""}, {missing})')
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)