Teaser 2686: Good innings
From The Sunday Times, 16th March 2014 [link] [link]
Tomorrow is St Patrick’s Day, so Pat will go on his usual tour of inns. Last year each inn had the same admission charge (made up of a two-figure number of pounds plus a two-figure number of pence surcharge). This four-figure total of pence happened to be the same as the four-figure number of pence Pat started the evening with, except that the order of the digits was reversed. In the first inn he spent one pound less than a third of what he had left after paying admission. In the second inn he also spent one pound less than a third of what he came in with after paying admission. That left him just enough to get into the third inn.
How much was that?
[teaser2686]




Jim Randell 9:57 am on 15 December 2022 Permalink |
The entry fee is a 4-digit number of pence, and Pat’s initial funds are the reverse of this number (also a 4-digit number).
As Pat pays 3 entry fees, each one cannot be more than £33.33, so we don’t need to check entry fees more than that.
Run: [ @replit ]
from enigma import (irange, nreverse, as_int, ediv, catch, printf) # check for viable spending pattern def check(entry): # starting amount is the reverse of the entry fee funds = start = nreverse(entry) # first pub funds = as_int(funds - entry, "+") spend1 = as_int(ediv(funds, 3) - 100, "+") funds = as_int(funds - spend1, "+") # second pub funds = as_int(funds - entry, "+") spend2 = as_int(ediv(funds, 3) - 100, "+") funds = as_int(funds - spend2, "+") # third pub funds = as_int(funds - entry, "0") # output solution printf("entry = {entry}; start = {start}; spend1 = {spend1}; spend2 = {spend2}") # consider 4-digit entry fees for entry in irange(1000, 3333): catch(check, entry)Solution: The entry fee was: £14.56.
So Pat’s finances go:
LikeLike