aboutsummaryrefslogtreecommitdiff
path: root/challenge-195/sgreen/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-195/sgreen/python')
-rwxr-xr-xchallenge-195/sgreen/python/ch-1.py31
-rwxr-xr-xchallenge-195/sgreen/python/ch-2.py29
2 files changed, 60 insertions, 0 deletions
diff --git a/challenge-195/sgreen/python/ch-1.py b/challenge-195/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..4b3831a16c
--- /dev/null
+++ b/challenge-195/sgreen/python/ch-1.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+import sys
+
+
+def is_simple_number(n):
+ # Determine if the number is simple
+ seen = {}
+ for i in str(n):
+ if i in seen:
+ # We've seen the digit before. It's not simple
+ return False
+ seen[i] = 1
+
+ # It is simple
+ return True
+
+
+def main(n):
+ # Iterate through the list counting the number of simple numbers
+ simple_count = 0
+ for i in range(1, n+1):
+ if is_simple_number(i):
+ simple_count += 1
+
+ # Print the result
+ print(simple_count)
+
+
+if __name__ == '__main__':
+ main(int(sys.argv[1]))
diff --git a/challenge-195/sgreen/python/ch-2.py b/challenge-195/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..0ba621b63f
--- /dev/null
+++ b/challenge-195/sgreen/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(array):
+ # Count the frequency of even numbers
+ evens = {}
+ for i in array:
+ if i % 2 == 0:
+ evens[i] = evens.get(i, 0) + 1
+
+ if not evens:
+ # If no evens, return -1
+ print(-1)
+ else:
+ # Find the evens that occur most often
+ m = max(evens.values())
+ max_evens = [i for i, v in evens.items() if v == m]
+
+ # The the minimum even that occurs most often
+ min_max_evens = min(max_evens)
+ print(min_max_evens)
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)