Sunday Times Teaser 2722 – A Simple Sum
by Ian Kay
Published Sunday November 23 2014 (link)
I have written down two three-figure numbers and one four-figure number: between them they use each of the digits 0 to 9 exactly once. In fact the four-figure number is the sum of the other two numbers.
If I told you how many of the three numbers were even, then it would be possible to work out the four-figure number.
What is it?
One Comment
Leave one →
-
brian gladman permalink123456789101112131415161718192021222324from itertools import combinations, permutationsfrom collections import defaultdictd = defaultdict(set)# pick the leading digits for the three digit numbers (exclude# one because this is the leading digit of the four digit sum)for p in combinations(range(2, 10), 2):# pick the other four digits for these numbersfor q in permutations(set(range(10)) - set(p + (1,)), 4):# form these two numbers and their sumn1 = 100 * p[0] + 10 * q[0] + q[1]n2 = 100 * p[1] + 10 * q[2] + q[3]n3 = n1 + n2# accumulate the set of digits used in the three numbersif len(set(p + q + tuple(int(x) for x in str(n3)))) == 10:# index solutions on how many of the numbers are oddd[(n1 & 1) + (n2 & 1) + (n3 & 1)].add(n3)# look for a count of odd numbers that leads to a single solutionfor nbr, *rest in tuple(d.values()):if not rest:print('The number is {}'.format(nbr))