aboutsummaryrefslogtreecommitdiff
path: root/challenge-284/sgreen/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-284/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-284/sgreen/python/ch-1.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-284/sgreen/python/ch-1.py b/challenge-284/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..2b7d01598f
--- /dev/null
+++ b/challenge-284/sgreen/python/ch-1.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+from collections import Counter
+import sys
+
+
+def lucky_integer(ints: list) -> str:
+ # Calculate the frequency of each integer
+ freq = Counter(ints)
+
+ # Work through the dict, highest first
+ for i in sorted(freq, reverse=True):
+ if i == freq[i]:
+ # We have the lucky integer
+ return i
+
+ # There is no lucky integer
+ return -1
+
+
+def main():
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ result = lucky_integer(array)
+ print(result)
+
+
+if __name__ == '__main__':
+ main()