Supposedly Trivial math question.

Levi Pearson levipearson at gmail.com
Tue Oct 1 11:18:27 MDT 2013

```On Tue, Oct 1, 2013 at 11:10 AM, Richard Holden <rholdeniii at gmail.com> wrote:
> 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
>

This is true, and is usable if you get the input in the form of a
string in the correct base.  If you get it as a number, either you or
a library function would have to do the divisions in order to convert
the number to a string in the correct base in the first place.  If
that's the case, there's no point in using a string; you might as well
use an array of digit values with the index as the power to which
you'll raise the base before multiplying.  The problem definition is
underspecified with respect to input/output, so it's not clear whether
this approach is valid or not, but it's certainly sound if it is
applicable.

--Levi
```