10235

# Coin Machine

This Demonstration shows a coin machine. Coins are available in denominations of 1, 5, 10, 25, and 50 cents and 1 dollar. Specific coins can be excluded and you can refill the machine. The coin machine can provide change for a given amount of money. Three algorithms are presented: the greedy algorithm, the optimal algorithm for the given system, and a random algorithm.

### DETAILS

A sequence where is called a currency or a coinage system. We always assume that is the smallest coin, so that every cash amount can be represented in the system in at least one way. In our case, any coinage system can be chosen using the coins available in the current US system, but the 1 cent coin must be included.
The change-making problem asks for the most efficient algorithm for the given coinage system (efficient in the sense of using the least number of coins). For most coinage systems, the greedy algorithm (which at each step chooses the maximum possible number of the largest denominations available) is optimal, but this is not true for general systems. Famously, this was not the case for the pre-decimal British coinage system.
The greedy algorithm is optimal for most subsets of ; however, it is not optimal for subsets , , , and . The first amount of money for which these coinage systems are not optimal is 30 cents. This can be verified using the Pearson test (see [1, 2]), which is implemented in this Demonstration. The smallest amount of money for which the optimal algorithm does not give the same answer as the greedy algorithm is 30 cents.
References
[1] M. Kleber, R. Vakil, and J. Shallit, "What This Country Needs Is an 18c Piece," Mathematical Intelligencer 25(2), 2003 pp. 20–23. doi: 10.1007/BF02984830.
[2] M. Adamaszek and A. Niewiarowska, "Combinatorics of the Change-Making Problem," European Journal of Combinatorics 31(1), 2010 pp. 47–63. arXiv:0801.0120v2.

### PERMANENT CITATION

 Share: Embed Interactive Demonstration New! Just copy and paste this snippet of JavaScript code into your website or blog to put the live Demonstration on your site. More details » Download Demonstration as CDF » Download Author Code »(preview ») Files require Wolfram CDF Player or Mathematica.

#### Related Topics

 RELATED RESOURCES
 The #1 tool for creating Demonstrations and anything technical. Explore anything with the first computational knowledge engine. The web's most extensive mathematics resource. An app for every course—right in the palm of your hand. Read our views on math,science, and technology. The format that makes Demonstrations (and any information) easy to share and interact with. Programs & resources for educators, schools & students. Join the initiative for modernizing math education. Walk through homework problems one step at a time, with hints to help along the way. Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet. Knowledge-based programming for everyone.