Spielerando

Let a merchant pay change from a purse that holds only some coins

When coins come in odd sizes and the merchant has only a few of each, the obvious way of counting out change can fail even though a payable way exists, or hand over far more coins than needed. This entry finds the fewest coins and says honestly when it cannot be done.

Why this works

Taking the biggest coin first is only a habit that happens to work for tidy coin sets. When coins are odd or scarce, the honest way is to try the combinations and check them, and to say plainly when the purse simply cannot pay out.

When not to use it

Don't count coins when the money is only a number in the corner of the screen and nobody handles pieces. Then change is just subtraction. Keep coin-level change for games where the purse itself is a puzzle or part of the drama of trading.

In the full entry

  • What to build, step by step
  • Starting values and the reason for each
  • 3 common mistakes and the fix
  • 37 lines of example code with 3 checks that pass
  • How your AI shows you that it works

Say this to your AI

Use the Spielerando entry "Let a merchant pay change from a purse that holds only some coins" (read_entry merchant-makes-change-with-the-coins-in-his-purse) in my game. Build it step by step, and show me how you checked that it works.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP