On Tue, Oct 1, 2013 at 10:42 AM, Lonnie Olson <[email protected]> wrote:
> On Tue, Oct 1, 2013 at 10:23 AM, Lonnie Olson <[email protected]> wrote:
>> Here's my attempt w/o any real fancy base2 stuff.
>
> And for bonus points on insufficient supply checking...
Oops, edit here.
>
> #!/usr/bin/python
>
> PRICE=123.45
> PAID=1300.0
> SUPPLY={
> 1000: 50,
> 100: 50,
> 10: 2,
> 1: 50,
> 0.1: 500,
> 0.01: 500
> }
>
> change=PAID-PRICE
>
> # Find largest denomination
> c=-3
> while True:
> if int(change/pow(10,c)) == 0:
> break
> c += 1
>
> while change>0:
> c-=1
> denomination = pow(10,c)
> bills = int(change/denomination)
> if SUPPLY[denomination] < bills:
> bills = SUPPLY[denomination]
> print "%d-%fs" % (bills,denomination)
> change -= bills*denomination
> change = round(change,2)
/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/