Sunday Times Teaser 2596 – Unusual Factors
by Nick MacKinnon
Published: 24 June 2012 (link)
There are no neat tests for divisibility by 7 or 13, so it’s unusual for these factors to feature in Teasers: today we put that right. If you start with any three different non-zero digits, then you can make six different three- figure numbers using precisely those digits. For example, with 2, 5 and 7 you get 257, 275, 527, 572, 725 and 752. Here, one of their differences (572 — 257) is divisible by 7, and another (725 — 257) is divisible by 13. Your task today is to find three different digits so that none of the six possible three- figure numbers and none of the differences between any pair of them is a multiple of either 7 or 13.
What are the three digits?
One Comment
Leave one →
-
Brian Gladman permalink123456789101112131415161718from itertools import combinations, permutationsfrom functools import reduce# pick the three non-zero digitsfor c in combinations(range(1, 10), 3):# compose the six numbers by permuting these digitsnbrs = [reduce(lambda x, y: 10 * x + y, p)for p in permutations(c)]# check that none are divisible by 7 or 13if all(n % i for i in (7, 13) for n in nbrs):# and that no difference between any pair of them# is divisible by 7 and 13if all((m - n) % i for i in (7, 13)for m, n in combinations(nbrs, 2)):s = ', '.join(str(x) for x in c).rpartition(',')print('The digits are {}.'.format(s[0] + ' and' + s[2]))