Sunday Times Teaser 2872 – Appropriate Arithmetic
by Victor Bryant
Published October 8 2017 (link)
I wrote down three two-figure numbers, one of which was double one of the others. Overall the three numbers used six consecutive digits between them. I then added up the three numbers to give a three-figure sum, and I also multiplied together the three numbers to give a five-figure product. Replacing digits consistently by letters my two answers, appropriately, were ADD and TIMES.
What were the three original numbers?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526272829from itertools import permutations# generate pairs of two digit numbers, one double# the other, that have four different digits from# a sequence of six consecutive digitsdef doubles():for x in range(10, 50):(a, b), (c, d) = divmod(x, 10), divmod(2 * x, 10)s = {a, b, c, d}if len(s) == 4 and max(s) - min(s) < 6:# return the two numbers and the set of their digitsyield x, 2 * x, sfor x, y, s in doubles():# find possible digits for the third numberp = set(range(max(0, max(s) - 5), min(10, min(s) + 6))).difference(s)for a, b in permutations(p, 2):z = 10 * a + badd = x + y + z# check that ADD has three digits, the last two the sameif 100 <= add < 1000 and (add // 10) % 10 == add % 10:times = x * y * z# check that TIMES has five digits and that ADD and TIMES have seven# different digits among themif 10000 <= times < 100000 and len(set(str(add) + str(times))) == 7:print('The numbers were {0:}, {1:} and {2:} (ADD = {3:}, TIMES = {4:}).'.format(*sorted((x, y, z)), add, times))