# Supposedly Trivial math question.

Lonnie Olson lists at kittypee.com
Tue Oct 1 10:47:14 MDT 2013

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

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)
```