aboutsummaryrefslogtreecommitdiff
path: root/challenge-215/sgreen/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-215/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-215/sgreen/python/ch-1.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/challenge-215/sgreen/python/ch-1.py b/challenge-215/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..b10b6e1547
--- /dev/null
+++ b/challenge-215/sgreen/python/ch-1.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(words):
+ current_word = words.pop(0)
+ unsorted_words = 0
+
+ if any(word < current_word for word in words):
+ # If the first word is not the smallest, the whole list is unsorted
+ print(len(words)+1)
+ return
+
+ for word in words:
+ if word >= current_word:
+ # The next word is in order
+ current_word = word
+ else:
+ # The word is less than the current word
+ unsorted_words += 1
+
+ print(unsorted_words)
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])