aboutsummaryrefslogtreecommitdiff
path: root/challenge-228/sgreen/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-228/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-228/sgreen/python/ch-2.py29
1 files changed, 29 insertions, 0 deletions
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)