Sunday Times Teaser 3328 – Loose Change
by Andrew Skidmore
Published Sunday July 05 2026 (link)
Elaine reminded Phil to take his suit to the dry cleaners. When Phil emptied his pockets he found he had exactly £5 in coins. All denominations of coin were represented (£2, £1, 50p, 20p, 10p, 5p, 2p and 1p) but there were more of one coin than any other.
Phil told all of this to Elaine, but she couldn’t work out how many coins Phil had. “If I told you the total two-figure number of coins you would be able to work out the numbers of each coin present”, said Phil.
Which denomination appeared most and how many of that coin were present?
6 Comments
Leave one →
I was mystified as to why Brian’s code which is very similar to mine, runs much faster. It turns out that having the coins/den tuple with coins in increasing order of value in my code as opposed to decreasing order in Brian’s code results in 4.5 times as many calls to the recursive function.
Hi John,
Yes, I found this out quite early on after originally using the increasing order.
But Frits also sent me a further speed up that he had found. When we are down to the last denomination, we don’t need to loop to find the number of coins needed since if the remainder is zero we add [0] to the output; if not we add [remainder // last denomination] provided this division is exact.
These two speed ups make a big difference to the speed. I also realised that your line 12 is not needed.
Frits’ speed up takes the number of calls of from 181603 down to 7772, a better than 23 to 1 ratio.
This is my fastest code so far (published on th S2T2 site). It can handle alternate denominations like [1, 4, 5, 7, 14, 15, 19, 35] and [4, 6, 8, 10, 12, 14, 34, 43] relatively well. It runs faster under PyPy.