Brain-Teaser 40: Christmas greetings
From The Sunday Times, 24th December 1961 [link]
The greetings above quite literally sum up my festive feelings, for they are, in fact, two simple addition sums in which each of which each digit has been replaced by an “Adventitious” letter. You are to replace each letter by the digit it stands for.
Having found the value of a letter in one of the sums, you must not assume that the letter necessarily retains that same value in the other sum. The two examples are quite independent apart from the one condition that the difference between the sum of the digits in MERRY and the sum of the digits in XMAS must be made as small as possible.
As I have already said — A Very Very Merry Xmas To One And All.
[teaser40]


Jim Randell 10:40 am on 18 July 2021 Permalink |
The following Python program uses the [[
SubstitutedSum]] solver from the enigma.py library to solve the alphametic sums, and then finds minimal distance solutions.It runs in 76ms.
Run: [ @replit ]
from itertools import product from enigma import SubstitutedSum, group, unpack, printf # sum 1: group solutions by M+E+R+R+Y p1 = SubstitutedSum(["A", "VERY", "VERY"], "MERRY") s1s = group(p1.solve(verbose=0), by=(lambda s: sum(s[x] for x in 'MERRY'))) # sum 2: group solutions by X+M+A+S p2 = SubstitutedSum(["XMAS", "TOONE"], "ANDALL") s2s = group(p2.solve(verbose=0), by=(lambda s: sum(s[x] for x in 'XMAS'))) # choose the pair with the minimal distance (k1, k2) = min(product(s1s.keys(), s2s.keys()), key=unpack(lambda x, y: abs(x - y))) # output solutions for (s1, s2) in product(s1s[k1], s2s[k2]): printf("(1) {s1}; (2) {s2}", s1=p1.substitute(s1, p1.text), s2=p2.substitute(s2, p2.text), )Solution: (i) 8 + 7492 + 7492 = 14992; (ii) 7618 + 95504 = 103122.
The first alphametic sum has 2 solutions:
The second alphametic sum has 2 solutions:
And the minimum distance is between M+E+R+R+Y = 25, and X + M + A + S = 22.
LikeLike
GeoffR 4:58 pm on 18 July 2021 Permalink |
LikeLike