aboutsummaryrefslogtreecommitdiff
path: root/challenge-208/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-03-19 11:12:01 +0000
committerGitHub <noreply@github.com>2023-03-19 11:12:01 +0000
commit44756ff6c2b4e10b9799f482ee31fda95a4c081f (patch)
tree984d3d97bb09839378ee198e462908874b3194d6 /challenge-208/sgreen/python/ch-2.py
parentfaa5a8079d332d30df9d7ce16d1461704dcea6ef (diff)
parent58100399bb455f719a2f13c3394aafb2932c0932 (diff)
downloadperlweeklychallenge-club-44756ff6c2b4e10b9799f482ee31fda95a4c081f.tar.gz
perlweeklychallenge-club-44756ff6c2b4e10b9799f482ee31fda95a4c081f.tar.bz2
perlweeklychallenge-club-44756ff6c2b4e10b9799f482ee31fda95a4c081f.zip
Merge pull request #7751 from simongreen-net/master
Simon's solution to challenge 208
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)