MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Need a Faster Solution to Number Theory Problem

I got hooked on the following little number theory problem which appears in
the August issue of Discovery magazine.  "Susan has more than one dollar in
change, but she still can't make exact change for a dollar bill. What is the
maximum amount of money that Susan could have in pennies, nickels, dimes and
quarters for this to be true?"
I solved the problem using the following Mathematica code:
Catch[Do[t=Times@@Length/@(Cases[dollar,{p_,n_,d_,q_}/; (p<=#1&&n<=#2 &&
d<=#3 && q<=#4)]&@@@FrobeniusSolve[coins,a]);
Starting with a maximum guess of $1.30 this gives the correct answer of
$1.19 in about 5 seconds.  The problem is that if the problem is made more
complicated by adding more possible coin denominations (and/or paper
currency) the execution time become very long indeed.
Is there a way to speed up the solution to this type of problem so that I
can handle more complicated cases in a reasonable time?

  • Prev by Date: Re: Colors in Plot[]
  • Next by Date: Re: Exported PDFs are too big in file size.
  • Previous by thread: Re: Re: Re: When is a List not a
  • Next by thread: Re: Need a Faster Solution to Number Theory Problem