aboutsummaryrefslogtreecommitdiff
path: root/challenge-237/sgreen/python/ch-2.py
blob: 51dbdc3f261e86608cad903f4798398329b2007e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)