diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-08-06 20:23:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-06 20:23:02 +0100 |
| commit | f73bdc52e13a5ba3c103473ffd97f796738ad288 (patch) | |
| tree | edc210833b90fe04291191ddd5bb41181bf1f194 /challenge-228/sgreen/python/ch-2.py | |
| parent | 136ab388fe1e976e9f0061c8088829555d81b86b (diff) | |
| parent | 48dfce1a0aeb235f2cdf6e8e84871e91bdf2c421 (diff) | |
| download | perlweeklychallenge-club-f73bdc52e13a5ba3c103473ffd97f796738ad288.tar.gz perlweeklychallenge-club-f73bdc52e13a5ba3c103473ffd97f796738ad288.tar.bz2 perlweeklychallenge-club-f73bdc52e13a5ba3c103473ffd97f796738ad288.zip | |
Merge pull request #8503 from simongreen-net/master
Simon's solution to challenge 228
Diffstat (limited to 'challenge-228/sgreen/python/ch-2.py')
| -rwxr-xr-x | challenge-228/sgreen/python/ch-2.py | 29 |
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) |
