Sunday Times Teaser 2797 – Sunday Times Table
by Susan Bricket
Published: 29 April 2016 (link)
Do you remember reciting your “times tables” — for example, “one seven is 7, two sevens are 14, three sevens are 21, continuing 28, 35, … and going on for ever? I have consistently replaced some digits by letters and in this way the five-figure number TIMES can be found in the times table of each of its digits but not in the times table of any other digit. On the other hand, TABLE can be found in the times table of seven different digits, each of which is a digit of TIMES or TABLE.
What number would be BEST?
One Comment
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223242526from itertools import permutationsfrom functools import reduce# permute the digits for TIMESfor p in permutations(range(1, 10), 5):TIMES = reduce(lambda x, y: 10 * x + y, p)# check that the digits of TIMES are all divisorsif not any(TIMES % x for x in p):# and that no other (non-zero) digits areothers = set(range(1, 10)).difference(p)if all(TIMES % x for x in others):T, I, M, E, S = p# permute the remaining digits for A, B and Lfor q in permutations(others.union([0]), 3):A, B, L = q# form the number TABLE and list its single digit divisorsTABLE = reduce(lambda x, y: 10 * x + y, (T, A, B, L, E))divs = [x for x in range(1, 10) if not TABLE % x]# of which there should be seven, all in TIMES or TABLEif len(divs) == 7 and all(x in p + q for x in divs):BEST = 1000 * B + 100 * E + 10 * S + Tfs = 'BEST = {} (TIMES = {}, TABLE = {}).'print(fs.format(BEST, TABLE, TIMES))