Coin Machine

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram CDF Player or other Wolfram Language products.

Requires a Wolfram Notebook System

Edit on desktop, mobile and cloud with any Wolfram Language product.

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.

Contributed by: Elzbieta Kukla, Teresa Ponikowska, and Michal Kijowski (July 2012)
With additional contributions by: Andrzej Kozlowski
Open content licensed under CC BY-NC-SA


Snapshots


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.



Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.
Send