Supposedly Trivial math question.

Lonnie Olson lists at kittypee.com
Tue Oct 1 10:42:58 MDT 2013


On Tue, Oct 1, 2013 at 10:23 AM, Lonnie Olson <lists at kittypee.com> 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)


More information about the PLUG mailing list