Brain-Teaser 4: [Digit substitution]
From The Sunday Times, 19th March 1961 [link]
The following is the test paper which Tom showed up:
8 + 7 = 62
59 + 4 = 50
5 + 3 = 5
11 × 1 = 55
12 + 8 = 23Naturally Miss Monk put five crosses on it. But Tom was indignant; for he was a self-taught boy and proud of his achievement. After some persuasion his teacher agreed to test him orally in addition and multiplication. This time Tom answered every question correctly.
Miss Monk was puzzled and then horrified when she discovered that although Tom had learnt to use arabic symbols he had ascribed to each an incorrect value. Fortunately he knew the meaning of + and × [and =].
If Tom were presented with the written problem: 751 × 7, what would his answer be?
This puzzle was originally published with no title.
[teaser4]
Jim Randell 12:12 pm on 2 August 2020 Permalink |
We can use the [[
SubstitutedExpression()]] solver from the enigma.py library to solve this puzzle.The following Python program runs in 55ms.
Run: [ @repl.it ]
from enigma import (SubstitutedExpression, substitute, map2str, printf) # the 5 expressions exprs = [ "{8} + {7} = {62}", "{59} + {4} = {50}", "{5} + {3} = {5}", "{11} * {1} = {55}", "{12} + {8} = {23}" ] # and the final expression expr = "{751} * {7}" # solve the expressions using the alphametic solver p = SubstitutedExpression(exprs, answer=expr, verbose=0) for (s, ans) in p.solve(): # and convert the answer back into symbols r = dict((str(v), int(k)) for (k, v) in s.items()) x = substitute(r, str(ans)) # output solution printf("{expr} -> {texpr} = {ans} <- {{{x}}} / {s}", texpr=p.substitute(s, expr), s=map2str(s, sep=" ", enc=""))Solution: Tom’s written answer would be 0622.
The map from Tom’s digits to standard digits is:
Tom uses 4 and 9 for the standard digits 2 and 5, but we can’t determine which way round.
To work out the answer, Tom would interpret the sum: 751 × 7, as: 893 × 8, which gives a result of 7144, but Tom would write this down as: 0622.
LikeLike
GeoffR 8:38 pm on 2 August 2020 Permalink |
# Equations # use a + b = cd # for 8 + 7 = 62 # use ef + g = eh # for 59 + 4 = 50 # use e + j = e # for 5 + 3 = 5 # use ii * i = ee # for 11 * 1 = 55 # use id + a = dj # for 12 + 8 = 23 # use bei * b = 751 * 7 for Tom's result from itertools import permutations digits = set(range(10)) # 1st stage permutation for p1 in permutations (digits, 4): a, b, c, d = p1 if a + b != 10*c + d: continue # 2nd stage permutation qs = digits.difference(p1) for p2 in permutations(qs, 4): e, f, g, h = p2 if e == 0: continue if 10*e + f + g != 10*e + h: continue # 3rd stage permutation qs2 = qs.difference(p2) for p3 in permutations(qs2): i, j = p3 if e + j != e: continue if 11 * i * i != 11 * e: continue if 10*i + d + a == 10*d + j: # Tom's answer res =(100*b + 10*e + i) * b print(f"Tom's answer = {res}") print(a,b,c,d,e,f,g,h,i,j) # 6 8 1 4 9 5 2 7 3 0 # Tom's answer is 7144 = hcdd in solution, # which is 0622 with variables used in original equations print(f"Equation 1: {a} + {b} = {10*c+d}") print(f"Equation 2: {10*e+f} + {g} = {10*e+h}") print(f"Equation 3: {e} + {j} = {e}") print(f"Equation 4: {11*i} * {i} = {11*e}") print(f"Equation 5: {10*i+d} + {a} = {10*d+j}") print() # Actual Equations # Equation 1: 6 + 8 = 14 # Equation 2: 92 + 5 = 97 or 95 + 2 = 97 # Equation 3: 9 + 0 = 9 # Equation 4: 33 * 3 = 99 # Equation 5: 34 + 6 = 40LikeLike