Sunday Times Teaser 2967 – Odds and Evens
by Angela Newing
Published August 4 2019 (link)
I have done a “long multiplication”, which is reproduced above. [If the multiplication was ABC x DE, then the third line shows the result of ABC x E and the fourth line shows the result of ABC x D]. However instead of writing the actual digits involved, I have written “o” where there is an odd digit and “e” where there is an even digit.
What is the result of the multiplication?
One Comment
Leave one →
-
Brian Gladman permalink12345678910111213141516171819202122from itertools import product# check that a string of digits matches an 'even-odd' (0, 1) templatedef check(s, tmpl):return len(s) == len(tmpl) and tuple(int(x) & 1 for x in s) == tmpl# The product is ABC x DE with A odd and the other digits evenfor A in range(1, 10, 2):for B, C in product(range(0, 10, 2), repeat=2):abc = 100 * A + 10 * B + Cfor D, E in product(range(2, 10, 2), repeat=2):de = 10 * D + E# form and check the length of the productr = str(abc * de)if check(r, (1, 1, 0, 0)):# form and check the lengths of the partial productst, b = str(E * abc), str(D * abc)if check(t, (0, 1, 0, 0)) and check(b, (0, 1, 0)):# collect and check the even and odd digitsprint(f"{abc} x {de} == {t} + {b} == {r}")