Re: Change for a Dollar



On Tue, 24 Apr 2007 13:20:47 -0500, Charles Richmond wrote:

I heard one night on David Letterman that there are
293 ways to make change for a dollar. So I started
thinking about writing a program to list out *all*
the ways a dollar could be broken into change. I
just can *not* seem to get a hold on this problem.

I wrote a program with a recursive function attempting
to make the change, but it had excessive runtime and
does *not* seem to be working in any case...

Does anyone have an idea how I can proceed???
I think it's easiest to get the design of recursive procedure
right if you generalise a bit. Suppose you have n coin values
C[0]..C[n-1], in increasing order. If W( S, m) is the number of ways
of making change for S using coins up to the m'th, we have
W(S,m) = Sum{ i>=0 with i*C[m]<S | W(S-i*C[m], m-1)}
This translates into code that takes a fraction of a second on
my (very ordinary) pc. If you want to generate a list of all
the ways its very similar, except you are concatenating strings
instead of adding numbers.
.



Relevant Pages

  • Re: 1885 nickels prices soared, but too high?
    ... prices for this coin over the more than five years that the reported ... Or, if they knew, why did they not report it? ... There's writing for money and writing for the love of writing. ... notice that they were reprints and it usually was clear from the context that this was ...
    (rec.collecting.coins)
  • Re: Lloyd "Skip" Press discusses his "old friend Jayne Hitchcock"
    ... Perhaps we should all sign up for bamboozling lessons then? ... is coin, starvation and whoredom innit. ... When it comes to writing, ... cuff, rough-and-tumble and raw, but it ain't crap. ...
    (misc.writing)
  • Re: Foreign coin ID?
    ... Anyone here with foreign coin expertise, ... looks like 1/4 of a sun's rays. ... More Arabic writing on top. ... five-pointed star beneath. ...
    (rec.collecting.coins)
  • Re: 1996 Eagles $40???
    ... Are you writing about SAE's? ... > I took an opportunity to catch up my eagle collection at the SJ Coin ... > horde or is it some irrational exuberance? ...
    (rec.collecting.coins)
  • Re: Foreign coin ID?
    ... Anyone here with foreign coin expertise, ... looks like 1/4 of a sun's rays. ... More Arabic writing on top. ... five-pointed star beneath. ...
    (rec.collecting.coins)