diff options
Diffstat (limited to 'challenge-236/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-236/sgreen/python/ch-1.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-236/sgreen/python/ch-1.py b/challenge-236/sgreen/python/ch-1.py new file mode 100755 index 0000000000..80ff481963 --- /dev/null +++ b/challenge-236/sgreen/python/ch-1.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 + +import sys + + +def main(notes): + # Store what is in the wallet, key is the dollar value, value is the + # number of notes we have + wallet = {} + + for customer_note in notes: + # Add the amount the person has given us + wallet[customer_note] = wallet.get(customer_note, 0) + 1 + + if customer_note == 5: + # No change required :) + continue + + change = customer_note - 5 + + # We try the bigger notes first + for wallet_note in sorted(wallet, reverse=True): + note_count = min(wallet[wallet_note], change // wallet_note) + if note_count > 0: + # Take the note from the wallet, and reduce the change still + # to give + wallet[wallet_note] -= note_count + change -= wallet_note * note_count + + if change == 0: + break + else: + print('false') + return + + print('true') + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) |
