Sunday Times Teaser 2950 – Ten Digits
by Andrew Skidmore
Published April 7 2019 (link)
Without repeating a digit I have written down three numbers, all greater than one.
Each number contains a different number of digits.
If I also write down the product of all three numbers, then the total number of digits I have used is ten.
The product contains only two different digits, each twice, neither of which appear in the three original numbers.
What is the product?
2 Comments
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122232425from itertools import combinations, permutationsfrom number_theory import divisor_pairs# The product uses four of the ten digits, leaving six for# the three numbers of different length; these must hence# be one, two and three digit numbers# pick the two different digits for the productfor U, V in combinations(range(10), 2):# consider all different arrangements of two of each digitfor p in set(x for x in permutations((U, U, V, V)) if x[0]):# form the product and partition it into 1, 2 and 3 digit# divisorsrhs = 1000 * p[0] + 100 * p[1] + 10 * p[2] + p[3]for A, BCDEF in divisor_pairs(rhs):if 1 < A < 10 and A not in {U, V}:for BC, DEF in divisor_pairs(BCDEF):if 10 <= BC < 100 <= DEF < 1000:B, C = divmod(BC, 10)D, E, F = (int(c) for c in str(DEF))if len({A, B, C, D, E, F, U, V}) == 8:print(f"{A} x {B}{C} x {D}{E}{F} == {rhs}")
-
GeoffR permalink1234567891011121314151617181920212223242526272829303132from itertools import permutationsdig_set = set(range(10))# The three numbers are A, BC and DEFfor p in permutations(range(10), 6):A, B, C, D, E, F = p# ensure that A > 1 and no leading zerosif A == 1 or 0 in {A, B, D}:continue# form the numbers and their productBC, DEF = 10 * B + C, 100 * D + 10 * E + Fans = A * BC * DEF# check that the answer has four digitsif 1000 <= ans < 10000:# extract the digits of the answerW, X, Y, Z = t = [int(c) for c in str(ans)]# check there are only two different digits and that# they are different from those in A, BC, and DEFans_set = set(t)if len(ans_set) == 2 and not ans_set.intersection(p):# check that each digit occurs twice in the answerif all(t.count(x) == 2 for x in ans_set):print(f"Answer: {ans} ({A} x {B}{C} x {D}{E}{F})")