Sunday Times Teaser 3158 – Digital Trio
by Danny Roth
Published Sunday April 02 2023 (link)
“I have a couple of subtraction problems for you”, George told Martha.
Look: N1 – N2 = N3 and N3 – N4 = N5.
Can you solve them if I tell you that N1, N3 and N5 are all three-digit whole numbers whose sum is less than 2000, the same three non-zero digits appearing in all three numbers but no digit being repeated within any of those numbers? N2 and N4 are both two-digit whole numbers using two of the three digits mentioned above, and the first digit of N1 is not equal to the first digit of N2.
What is N1?
2 Comments
Leave one →
-
Brian Gladman permalink1234567891011121314151617181920212223from itertools import combinations, permutations# choose the three non-zero digitsfor nzd3 in combinations('123456789', 3):# form the six different three digit numbers with these digitsn6 = sorted(int(''.join(s)) for s in permutations(nzd3))# pick three of them for N1, N3 and N5 with N5 < N3 < N1for N5, N3, N1 in combinations(n6, 3):# derive N2 and N4, check that N2 and N4 have two digits and check the sumif (10 <= (N2 := N1 - N3) < 100 and 10 <= (N4 := N3 - N5) < 100and N1 + N3 + N5 < 2000):# check that N1 and N2 have different leading digits and that N2 and N4# each use exactly two (the same two) of the three original digitsif N1 // 100 != N2 // 10:s_n2, s_n4, s_nzd3 = set(str(N2)), set(str(N4)), set(nzd3)if len(s_n2 & s_nzd3) == len(s_n4 & s_nzd3) == 2 and (s_n2 | s_n4) < s_nzd3:print(f"({N1 = }) - ({N2 = }) ==> ({N3 = }) - ({N4 = }) ==> ({N5 = }).")
-
John Z permalink1234567891011121314151617181920212223from itertools import permutations# pick three non zero digits and shuffle for N1for N1, N1s in ((int(''.join(n)), n) for n in permutations('123456789', 3)):# N2 is a permutation of 2 of those three digits, first digit conditionfor N2 in (int(''.join(n)) for n in permutations(N1s, 2) if n[0] != N1s[0]):N3 = N1 - N2# does N3 have the same three digits as N1if set(str(N3)) == (set(N1s)):# N4 is a permutation of 2 of those three digitsfor N4 in (int(''.join(n)) for n in permutations(N1s, 2)):N5 = N3 - N4# sum of N1, N3, N5 < 2000 and N5 has the same digits as N1if N1 + N3 + N5 < 2000 and set(str(N5)) == (set(N1s)):print(f'{N1 = }, {N2 = }, {N3 = }, {N4 = }, {N5 = }')