aboutsummaryrefslogtreecommitdiff
path: root/challenge-237/sgreen/python/ch-2.py
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2023-10-08 23:02:48 +1100
committerSimon Green <mail@simon.green>2023-10-08 23:02:48 +1100
commit79ea77999ba709f30b32931b73e8520202ba78b9 (patch)
tree73193cd386b127ddb8a836a6dddd965e6175acc0 /challenge-237/sgreen/python/ch-2.py
parent81695c46183ba0154c05412705e0e85a632d32a0 (diff)
downloadperlweeklychallenge-club-79ea77999ba709f30b32931b73e8520202ba78b9.tar.gz
perlweeklychallenge-club-79ea77999ba709f30b32931b73e8520202ba78b9.tar.bz2
perlweeklychallenge-club-79ea77999ba709f30b32931b73e8520202ba78b9.zip
Simon's solution to challenge 237
Diffstat (limited to 'challenge-237/sgreen/python/ch-2.py')
-rwxr-xr-xchallenge-237/sgreen/python/ch-2.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-237/sgreen/python/ch-2.py b/challenge-237/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..51dbdc3f26
--- /dev/null
+++ b/challenge-237/sgreen/python/ch-2.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(ints):
+ sorted_ints = sorted(ints, reverse=True)
+ count = 0
+
+ for i in sorted_ints:
+ # If there isn't a solution, exit the loop
+ if min(ints) >= i:
+ break
+
+ # Find the position of the maximum value < i, and delete it
+ m = max(j for j in ints if j < i)
+ idx = ints.index(m)
+ del ints[idx]
+
+ count += 1
+
+ # Print the solution
+ print(count)
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ main(array)