All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Intuitive Coins (Posted on 2005-03-29) Difficulty: 3 of 5
If you must pay an amount in coins, the "intuitive" algorithm is: pay as much as possible with the largest denomination coin, and then go on to pay the rest with the other coins. For example, if there are 25, 5 and 1 cent coins, to pay someone 32 cents, you'd first give him a 25 cents coin, then one 5 cent coin, and finally two 1 cent coins.)

However, this doesn't always end paying with as few coins as possible: if we had 25, 10 and 1 cent coins, paying 32 cents with the "intuitive" algorithm would use 8 coins, while three 10 cent coins and two 1 cent coins would be better.

We can call a set "intuitive", if the "intuitive algorithm" always pays out any amount with as few coins as possible.

The problem: give an algorithm that allows you to decide that {25,5,1} is an "intuitive" set, while {25,10,1} isn't.

See The Solution Submitted by Federico Kereki    
Rating: 3.8000 (5 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution re: There's more to it.... (solution? spoiler?) -- larger sets | Comment 8 of 14 |
(In reply to There's more to it.... (solution? spoiler?) by Erik O.)

When examining larger sets, it is not sufficient to check merely the smallest number that is divisible by a given denomination but larger than the next higher denomination, but higher multiples of the given denomination as well.

Consider {5,4,3,1} for an amount = 12. The intuitive algorithm uses 4 coins, while you really only need three 4's. According to the algorithm previously presented, we would only test two 4's = 8, and that would pass this set as intuitive, though it is not. In the 3-denomination set {5,4,1} the 8 test would have been sufficient.

In {6,5,4,2,1}, 15 requires 5 by the intuitive algorithm, but takes three fives, while the preceding solution would have called for checking only 2x5=10.

I think it safest to check all multiples of each denomination up to the least common multiple of the entire set of denominations.

  Posted by Charlie on 2005-03-30 19:40:13
Please log in:
Remember me:
Sign up! | Forgot password

Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (0)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Copyright © 2002 - 2018 by Animus Pactum Consulting. All rights reserved. Privacy Information