Hmm set the 'arbitrary' base as base 2 and just use the bits :) http://ideone.com/lxkd6c
Not very useful for converting to anything other than base 2 though. -John Shaver On Tue, Oct 1, 2013 at 2:48 PM, S. Dale Morrey <[email protected]>wrote: > static count x=1 was supposed to be static count =1; Then a count++ there > somewhere before the loop > > > On Tue, Oct 1, 2013 at 2:45 PM, S. Dale Morrey <[email protected] > >wrote: > > > > > The base is arbitrary, meaning if the customer is giving base 10 money > > then all change must be base 10, i.e. 1's 10s, 100's etc. As stated > > earlier each bill is a power of the previous bill, there are no 0.25's or > > 20's or other Americanisms to deal with. What we would call 25 cents, > > would optimally be handled (in base 10) with 2 tens and 5 ones, there > would > > not be a 25 coin bill. > > Near the end he allowed me to just pick a base and lock my answer to > that, > > i.e. I no longer had to account for a different base. So I included that > > in the instructions upfront. > > > > My solution (which I've only recently worked out), looks like this. > > > > function makeChange(int base, int amountDue, int amountGiven){ > > > > changeDue = amountGiven - amountDue; > > return breakBills(changeDue, base); > > } > > > > function breakBills(int amount,int base ){ > > static count x = 1; > > dividend = floor(amount / base); > > remainder = amount mod base; > > if(remainder == 0){ > > return; > > }else{ > > return dividend+"-" + (count * base) + "'s, " + > > breakBills(remainder,base); > > } > > > > } > > > > Theoretically this might be javascript, frankly it's out of thing air, I > > haven't tested it yet, but it looks like it should work right? > > > > } > > > > > > > > > > > > On Tue, Oct 1, 2013 at 11:18 AM, Levi Pearson <[email protected] > >wrote: > > > >> On Tue, Oct 1, 2013 at 11:10 AM, Richard Holden <[email protected]> > >> 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 > >> > >> /* > >> PLUG: http://plug.org, #utah on irc.freenode.net > >> Unsubscribe: http://plug.org/mailman/options/plug > >> Don't fear the penguin. > >> */ > >> > > > > > > /* > PLUG: http://plug.org, #utah on irc.freenode.net > Unsubscribe: http://plug.org/mailman/options/plug > Don't fear the penguin. > */ > /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */
