# Enigmatic Code

Programming Enigma Puzzles

## Enigma 171: Addition: digits all wrong

From New Scientist #1316, 29th July 1982 [link]

In the above addition sum all the digits are wrong. But the same wrong digit stands for the same correct digit wherever it appears, and the same correct digit is always represented by the same wrong digit.

There is no actual question asked by this puzzle, but I think we can safely assume that the answer is the sum written out using the correct digits.

This puzzle had been previously published in New Scientist #1137 (11th January 1979) as Puzzle 85.

[enigma171]

### 2 responses to “Enigma 171: Addition: digits all wrong”

1. Jim Randell 23 February 2014 at 8:40 am

The [[ `SubstitutedSum()` ]] solver from enigma.py makes short work of this problem. It runs in 44ms.

```from enigma import SubstitutedSum

# invalid assignments
d2i = {
# no leading zeros
0: '016',
# digits cannot stand for themselves
1: '1', 3: '3', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9',
}

SubstitutedSum(['1939', '1079'], '6856', d2i=d2i).go()
```

Solution: The correct sum is 2767 + 2137 = 4904.

• geoffrounce 6 October 2014 at 10:37 am

In my permutation solution, I start by excluding digits which cannot form the answer:

```#  1 9 3 9     a i c i
#  1 0 7 9     a j g i
#  -------       -------
#  6 8 5 6     f h e f
#  -------       -------

from itertools import permutations

for p in permutations('3124567890',8):
a,c,e,f,g,h,i,j = p
if a != '1' and c != '3' and e != '5' \
and f != '6' and g != '7' and h != '8' \
and i != '9' and j != '0':
if a != '0' and f != '0':
aici = int(a+i+c+i)
ajgi = int(a+j+g+i)
fhef = int(f+h+e+f)
if aici + ajgi == fhef:
print(aici,'+',ajgi, '=', fhef)

# Ans: 2767 + 2137 = 4904

```

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