go ahead... be a heretic | |
PerlMonks |
Re: puzzle: how many ways to make $100by rhesa (Vicar) |
on Apr 29, 2006 at 00:21 UTC ( [id://546445]=note: print w/replies, xml ) | Need Help?? |
You're looking for the Greedy Algorithm. It's basically the reverse from your approach: you start out with the highest denomination, then decrease that and spread the difference among the lower denominations.
Here's one link: http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Greedy/greedyIntro.htm I dug up my solution to problem 31 on Project Euler.
It could use some refactoring, but I was in a hurry and I didn't write it for public consumption ;) Update: Oh right, yes, output... I get Total found: 4563.
In Section
Seekers of Perl Wisdom
|
|