# Enigmatic Code

Programming Enigma Puzzles

## Enigma 29: One letter wrong

From New Scientist #1171, 6th September 1979 [link]

In this addition sum, with letters substituted for digits, there is, I’m afraid, a mistake. The first two lines across are correct, but in the third line across there has been a mistake and one of the letters is incorrect. Apart from this unfortunate error (due of course to Uncle Bungle) each letter stands for the same digit wherever it appears and different letters stand for different digits. Find the mistake and write out the correct addition sum.

Note: When it’s talking about “first two lines across” it is referring to the summands, and the “third line across” refers to the result of the sum.

[enigma29]

### One response to “Enigma 29: One letter wrong”

1. Jim Randell 31 December 2012 at 9:15 am

The following Python program runs in 731ms.

```from itertools import permutations
from enigma import irange, nconcat, split, printf

ds = irange(0, 9)
for s in permutations(ds, 6):
(H, B, D, M, P, A) = s
if H == 0: continue
a = nconcat(H, B, B, D, B, M, D, B)
b = nconcat(H, B, B, B, P, A, D, B)
c = a + b
d = list(split(c, int))
# the result should have 9 digits
if len(d) != 9: continue
# which digit of the result is wrong?
f = (d != M,
d != B,
d != H,
d in s,
d in s + (d,),
d in s + (d, d),
d in s + (d, d, d),
d != B,
d != H)
# only one of these should be true
if len(list(x for x in f if x)) != 1: continue

n = f.index(True) + 1
printf("{a} + {b} = {c}, digit {n} of original result is incorrect")
```

Solution: The second digit, B, of the result should have been P. So, the result of the sum should have been written `MPHEGTXBH`. The correct sum is 84474174 + 84446374 = 168920548.

This site uses Akismet to reduce spam. Learn how your comment data is processed.