aboutsummaryrefslogtreecommitdiff
path: root/challenge-228/sgreen/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-228/sgreen/python')
-rwxr-xr-xchallenge-228/sgreen/python/ch-1.py20
-rwxr-xr-xchallenge-228/sgreen/python/ch-2.py29
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-228/sgreen/python/ch-1.py b/challenge-228/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..039b606169
--- /dev/null
+++ b/challenge-228/sgreen/python/ch-1.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(ints):
+ # Get the frequency of all numbers
+ freq = {}
+ for i in ints:
+ freq[i] = 1 + freq.get(i, 0)
+
+ # Get the sum of all unique values
+ solution = sum(i for i in freq if freq[i] == 1)
+ print(solution)
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ main(array)
diff --git a/challenge-228/sgreen/python/ch-2.py b/challenge-228/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..5422a435d1
--- /dev/null
+++ b/challenge-228/sgreen/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(ints):
+ # Get the minimum value
+ moves = 0
+ min_int = min(ints)
+
+ while len(ints):
+ moves += 1
+ value = ints.pop(0)
+
+ # If this is the minimum value, calculate the new minimum value
+ if value == min_int:
+ if len(ints):
+ min_int = min(ints)
+ else:
+ # Move it to the end
+ ints.append(value)
+
+ print(moves)
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ main(array)