# Enigmatic Code

Programming Enigma Puzzles

## Enigma 392: Nothing written right

From New Scientist #1542, 8th January 1987 [link]

In the following 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.

[enigma392]

### 2 responses to “Enigma 392: Nothing written right”

1. Jim Randell 21 April 2017 at 7:18 am

The SubstitutedSum() solver from the enigma.py library makes short work of this problem.

This Python code runs in 41ms.

```from enigma import SubstitutedSum

SubstitutedSum(
['7086', '2346'], '34654',
d2i={ 0: '0237', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8' }
).go()
```

Solution: The correct sum is: 2465 + 8105 = 10570.

2. geoffrounce 21 April 2017 at 8:51 am
```% A Solution in MiniZinc
% Substituting letters for the wrong digits, the sum is:
%  ABCD
%+ EFGD
% -----
% FGDHG
% -----

include "globals.mzn";

var 1..9:A;  var 0..9:B;  var 0..9:C;  var 0..9:D;
var 1..9:E;  var 1..9:F;  var 0..9:G;  var 0..9:H;

constraint alldifferent([A,B,C,D,E,F,G,H]);

var 1000..9999: ABCD = 1000*A + 100*B + 10*C + D;
var 1000..9999: EFGD = 1000*E + 100*F + 10*G + D;
var 10000..99999: FGDHG = 10000*F + 1000*G + 100*D + 10*H + G;

constraint ABCD + EFGD == FGDHG /\
A != 7 /\ B != 0 /\ C != 8 /\ D != 6 /\
E != 2 /\ F != 3 /\ G != 4 /\ H != 5;

solve satisfy;

output [ show(ABCD) ++ " + "  ++ show(EFGD) ++ " = " ++ show(FGDHG) ];

% 2465 + 8105 = 10570
% Finished in 80msec
```