Sunday Times Teaser 2956 – A Nice Little Earner
by Graham Smithers
Published May 19 2019 (link)
The “value” of a number is found by subtracting its first digit from the last. For example, 6, 72, 88 and 164 have values 0, – 5, 0 and 3 respectively.
Raising funds for a local charity, I placed some raffle tickets numbered from 1 up to a certain 3-digit number, in a box. Participants then selected a ticket at random. If the value of their number was positive, they won that amount in £; if the value was negative, they contributed that amount in £. Otherwise no money changed hands.
All the tickets having been used, the total amount raised in £ was a rearrangement of the digits in that number of tickets.
How much was raised?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112cash = 0# consider the number of tickets raffledfor nbr in range(1, 1000):s = str(nbr)# find the amount raised for this number of ticketscash -= int(s[-1]) - int(s[0])# if the income is positive, check if the amount# raised and the ticket number have the same digitsif cash > 0 and sorted(s) == sorted(str(cash)):print(f"£{cash} was raised.")