Supposedly Trivial math question.

Richard Holden rholdeniii at gmail.com
Tue Oct 1 11:10:09 MDT 2013


Unless I'm reading it wrong it doesn't actually seem to require all of the
division. They say that the smallest fractional unit can be taken to be a
whole unit, so in the values stated the 123.45 and 1300.00 get changed to
whole units as 12345 integer and 130000 integer. That gives us the
calculation for the integer change as

 130000
- 12345
-------
 117655

To figure out the change we just convert the integer into a string
(assuming that the language of choice correctly converts) which should give
us "117655". If we reverse the string ("556711") and iterate over the
characters then the index becomes the power to which we raise the base.
i.e. pulling out the second 5 (index value 1) we could output 5-(10^1)s or
5-10s, etc. Giving "5-1s 5-10s 6-100s 7-1000s 1-10000s 1-100000s"

To do this in base 2 it just becomes
5-(2^0)s 5-(2^1)s 6-(2^2)s 7-(2^3)s 1-(2^4)s 1-(2^5)s

-Richard Holden




On Tue, Oct 1, 2013 at 10:47 AM, Lonnie Olson <lists at kittypee.com> wrote:

> 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)
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>


More information about the PLUG mailing list