# Enigmatic Code

Programming Enigma Puzzles

## Puzzle 16: Addition. Digits all wrong

From New Scientist #1067, 1st September 1977 [link]

Each digit in the addition sum below is 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. Find the correct addition sum.

[puzzle16]

### 2 responses to “Puzzle 16: Addition. Digits all wrong”

1. Jim Randell 14 August 2019 at 10:11 am

We can use the [[ SubstitutedSum() ]] solver from the enigma.py library to solve this puzzle. While it can cope with using the digits as symbols (which cannot stand for themselves). I think it is easier to understand if we replace the digits 1, 4, 7, 8 by the symbols A, B, C, D and solve the equivalent sum: BDA + BDB = CBC.

The following run file executes in 137ms.

Run: [ @repl.it ]

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

SubstitutedSum

--invalid="1,A"
--invalid="4,B"
--invalid="7,C"
--invalid="8,D"

"BDA + BDB = CBC"
```

Solution: The correct sum is: 263 + 262 = 525.

2. GeoffR 14 August 2019 at 12:17 pm
```% A Solution in MiniZinc
include "globals.mzn";

%  481  ABC  263
%  484  DEF  262
%  ---  ---  ---
%  747  GHI  525
%  ---  ---  ---

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;

% Leading digits cannot be zero
constraint A > 0 /\ D > 0 /\ G > 0;

% New digits cannot equal puzzle digits
constraint A != 4 /\ B != 8 /\ C != 1
/\ D != 4 /\ E != 8 /\ F != 4
/\ G != 7 /\ H != 4 /\ I != 7;

% New digits must follow same pattern as puzzle digits
constraint A == D /\ A == F /\ A == H;
constraint G == I /\ B == E /\ C != F;

var 100..999: ABC = 100*A + 10*B + C;
var 100..999: DEF = 100*D + 10*E + F;
var 100..999: GHI = 100*G + 10*H + I;

constraint ABC + DEF == GHI;

solve satisfy;

output ["Correct sum is " ++ show(ABC) ++ " + "
++ show(DEF) ++ " = " ++ show(GHI) ];

% Correct sum is 263 + 262 = 525
% ----------
% ==========
```

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