Enigmatic Code

Programming Enigma Puzzles

Enigma 397: All wrong again

From New Scientist #1547, 12th February 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.

[enigma397]

3 responses to “Enigma 397: All wrong again”

1. Jim Randell 26 May 2017 at 5:44 am

Yet another substituted addition sum. Again the SubstitutedSum() solver from the enigma.py library makes short work of it. This Python program runs in 63ms.

```from enigma import SubstitutedSum

SubstitutedSum(
['82372', '92372', '81462'], '110591',
d2i={ 0: '0189', 1: '1', 2: '2', 3: '3', 4: '4', 5: '5', 6: '6', 7: '7', 8: '8', 9: '9' }
).go()
```

Solution: The correct sum is: 94564 + 34564 + 92704 = 221832.

Or as a run file:

```#!/usr/bin/env python -m enigma -r

SubstitutedSum

--invalid="0,0189"
--invalid="1,1"
--invalid="2,2"
--invalid="3,3"
--invalid="4,4"
--invalid="5,5"
--invalid="6,6"
--invalid="7,7"
--invalid="8,8"
--invalid="9,9"

"82372 + 92372 + 81462 = 110591"
```
2. Hugh Casement 26 May 2017 at 6:56 am

To avoid confusion if solving “on foot”, it may help first to substitute letters, for example

FENCE
HENCE
FABLE
AARDVA

3. geoffrounce 26 May 2017 at 9:05 pm
```% A Solution in MiniZinc
% Try A,B,C,D,E,F,G,H,I,J = 1,2,3,4,5,6,7,8,9,0
% So the incorrect substitution sum is HBCGB + IBCGB + HADFB = AAJEIA

include "globals.mzn";

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

constraint alldifferent([A,B,C,D,E,F,G,H,I,J]);
constraint H > 0 /\ I > 0 /\ A > 0;

% For the correct addition sum:
constraint A != 1 /\ B != 2 /\ C != 3 /\ D != 4 /\ E != 5
/\ F != 6 /\ G != 7 /\ H != 8 /\ I != 9 /\ J != 0;

% Components of the sum
var 10000..99999 : HBCGB = 10000*H + 1000*B + 100*C + 10*G + B;
var 10000..99999 : IBCGB = 10000*I + 1000*B + 100*C + 10*G + B;
var 10000..99999 : HADFB = 10000*H + 1000*A + 100*D + 10*F + B;
var 100000..999999 : AAJEIA = 100000*A + 10000*A + 1000*J + 100*E + 10*I + A;

constraint HBCGB + IBCGB + HADFB = AAJEIA;

solve satisfy;

output [ "Correct addition sum is " ++ show(HBCGB) ++ " + " ++ show(IBCGB) ++
" + " ++ show(HADFB)++ " = " ++ show(AAJEIA)] ;

% Correct addition sum is 94564 + 34564 + 92704 = 221832
% Finished in 142msec
```

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