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...
#!/usr/bin/python
PRICE=123.45
PAID=1300.0
SUPPLY={
1000: 50,
100: 0,
10: 50,
1: 50,
0.1: 50,
0.01: 50
}
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:
continue
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.
*/