Change for One Dollar (change) Problem : A customer entered a shop and asked to change a single dollar for coins. The cashier said: I am sorry, but I can not change it with the coins I have. The customer then asked for change of a half dollar, but the cashier replied: I am sorry, but I can not change it with the coins I have. The customer asked for a change of a quarter, then a dime, then a nickel, but for all these requests the cashier kept replying: I am sorry, but I can not change it with the coins I have. Finally, the customer got upset and asked: Do you have any coins at all? The cashier replied: Yes ... I have $ 1.15 in coins. The question is: what coins were in the cash register? (This puzzle is from [2], Puzzle 5-5.) Modeling Steps a, b , c , d , We introduce ve integer variables and e to be the number of 50-cents, 25-cents (quarter), 10-cents (dime), 5-cents (nickel), and 1-cent coins in the cash register. 1. There was $ 1.15 in the cash register. That means: 50a + 25b + 10c + 5d + 1e = 115 2. Since the cashier could not change a dollar, he must have at most one 50-cents coin, since otherwise he has at least two and then could make the change. a≤1 since 50a ≤ 99 (or 50a < 100) 3. In the same way we have: b≤3 c≤9 d ≤ 19 e ≤ 99 since 25b ≤ 99 10c ≤ 99 5d ≤ 99 1e ≤ 99 Solving the problem with the requirements just given, the problem would have many dierent solutions, which are not correct. For example, the cash register could have 1 half dollar coin, two quarters, one dime and one nickel in the cash register, or he could hold 19 nickels and 20 1-cent coins. All solution that are not correct, because then he could change one dollar. We see the problem: If there is one 50-cents coin in the cash register then there can only be one quarter there, otherwise he could change one dollar. Hence we have: 50a + 25b ≤ 99 The fact, however, that he cannot change one half a dollar means that c ≤ 4. The fact that he cannot change a dime means change a nickel means d ≤ 1, b ≤ 1 and and the fact that he cannot e ≤ 4. The complete model code in LPL for this model is as follows (see [1]): Listing 1: The Model model change "Change for One Dollar"; integer variable a [0..1] "number of 50-cent coins"; 1 b [0..1] "number c [0..4] "number d [0..1] "number e [0..4] "number constraint A: 50*a solve; Write(’(a,b,c,d,e) end Solution Question of 25-cent coins"; of 10-cent coins"; of 5-cent coins"; of 1-cent coins"; + 25*b + 10*c + 5*d + 1*e = 115; = (%d,%d,%d,%d,%d)\n’,a,b,c,d,e); : The unique solution is; one 50-cents coin, one quarter, and four dimes. (Answer see ) 1. Argue why the solution is unique. 2. What is the maximal amount the cash register could contain supposing that the cashier cannot change one dollar? What is the minimal amount? 3. Remove the requirements for this and the next questions that the cashier cannot change 50, 25, 10, or 5-cents. He just cannot change one dollar with the $ 1.15. What is the minimal and the maximal number of coins he could have? 4. The cashier said that he has exactly 7 coins in the cash register, Can you nd out what coins he has? 5. Is there also a solution with Answer 1. a 8 coins? (Question see ) and b Since b = 1 it d = 0, otherwise the sum 115 would not be attained, the same argument e = 0. It follows that c = 4 to reach the sum of 115. must be one, otherwise we would not have enough coins. follows that holds for 2. The maximal value is $ 1.24. Take the upper limit on all coins: 50 · 1 + 25 · 1 + 10 · 4 + 5 · 1 + 1 · 4 = 124 The minimal amount is one 1-cent coin, because the cashier said that he has some coins. 3. The minimal number is 5: two 50-cents coins and three nickels. The result is found 1 by model change1 : model change1 "Change for one dollar"; integer variable a [0..1] "number of 50-cent coins"; b [0..3] "number of 25-cent coins"; c [0..9] "number of 10-cent coins"; d [0..19] "number of 5-cent coins"; e [0..99] "number of 1-cent coins"; constraint A: 50*a + 25*b + 10*c + 5*d + 1*e = 115; B: 50*a + 25*b <= 99; C: a+b+c+d+e=7; minimize nrCoins: a+b+c+d+e; --maximize nrCoins: a+b+c+d+e; Write(’(a,b,c,d,e) = (%d,%d,%d,%d,%d)\n’,a,b,c,d,e); end 1 http://lpl.unifr.ch/lpl/Solver.jsp?name=/change1 2 B (why?). The maximal nummaximize in place of minimize Note that it was necessary to add an constraint called ber is 99: four nickels and 95 1-cent coins. (Use in model change1.) 4. Use model change1 and add the constraint: a + b + c + d + e = 7, The solution is: three quarters and four dimes. Then solve. This solution is unique, because minimizing once and then maximizing gives the same solution. (One needs to check that the solution does not contain a change of one dollar!) 5. No! Replace the previous constraint to a + b + c + d + e = 8, Then solve. LPL says that the problem is infeasible. References [1] T. Hürlimann. Reference Manual for the LPL Modelling Language, most recent version. www.virtual-optima.com. [2] Michalewicz M. Michalewicz Z. Puzzle-Based Learning: An introduction to critical thinking, mathematics, and problem solving. Hybrid Publishers, Melbourne Victoria, Australia, 2014, (rst edition 2008). 3
© Copyright 2026 Paperzz