Sunday Times Teaser 2920 – Barcode
by Ian Gilchrist
Published September 9 2018 (link)
When Fred opened his “10 to 99 Store” (the numbers reflecting the prices of the goods in pounds) there was trouble from the start when the barcode reader scanned the prices backwards. First at the self-service checkout was Mrs Adams, who kept quiet when she was charged £59.49 for a £94.95 item. The next two customers, Mr Baker and Mr Coles, paid by card, without noticing they had in fact been overcharged. All three had bought a differently-priced item, and by coincidence, in the case of the two men, the price each had been charged was a whole multiple of the actual price.
How much had the shop lost or gained overall on the three transaction?
2 Comments
Leave one →
-
Brian Gladman permalink123456789101112131415# the initial transaction (all values in pence)tx = [(9495, 5949)]# look for four digit numbers whose 'digit# reversed' values are multiples of themfor p in range(1000, 5000):c = int(str(p)[::-1])if c > p and not c % p:tx.append((p, c))for p, c in tx:print(f'item price £{p / 100:.2f} charged at £{c / 100:.2f}')ps, cs = (sum(x) for x in zip(*tx))print(f"A {'gain' if cs > ps else 'loss'} of £{abs(cs - ps) / 100:.2f}")
-
GeoffR permalink1234567891011121314151617181920212223242526nums = []# price range £10 - £99 (in pence)for n in range(1000, 9901):# nr must be a 4-digit number greater than nnr = int(str(n)[::-1])if nr < n or len(set(str(nr))) < 4:continueif nr % n == 0:nums.append((nr, n, nr - n))# undercharge for Mrs Adams first purchase (in pence)undercharge = 9495 - 5949# we need 2 more items only for Mr Baker and Mr Coles purchasestotal = 0if len(nums) == 2:# total sum for overcharged itemsfor a in nums:total += a[2]if total > undercharge:overcharge = total - underchargeprint('Total Overcharge = £{:.2f}'.format(overcharge / 100))