**From New Scientist #2269, 16th December 2000** [link]

In the multiplications shown, where the combined products of multiplications (I) and (II) (both identical) equal the product of multiplication (III), each letter consistently represents a specific digit, different letters being used for different digits while asterisks can be any digit.

The multiplications in fact are not difficult to solve, and easier still if I told you that TEN is even.

How much is TWENTY?

[enigma1113]

### Like this:

Like Loading...

*Related*

The first two multiplication sums are the same, so TWENTY is twice the result.

I’ve recently changed the internals of the

SubstitutedExpression()solver so that you can specify the alphametic component of expressions using curly braces. This means you don’t have to explicitly specify the symbols used via the--symbolsparameter, and allows you to use functions in expressions that would otherwise clash with the alphametic symbols (for example, in the code below, the “a” and “c” in the calls tomatch()are not interpreted as alphametic symbols, as they are not enclosed in curly braces, whereas as the “a” and “c” in{abc} * {TEN}are).As you’ve probably noticed I’ve also recently added the

match()function to theenigma.pylibrary, this matches the first argument (as a string) against the template given in the second argument. It is a repackaging of thefnmatch.fnmatch()function from the Python standard library, rather than using regular expressions.This following run file executes in 419ms.

Solution:TWENTY = 109416.The first two multiplication sums are: 282 × 194 = 54708 (= 1128 + 2538_ + 282__).

The third sum is: 141 × 776 = 109416 (= 846 + 987_ + 987__).

I mostly used your layout for the multiplication tables and found the requirement for TEN to be even not strictly necessary.

I also found multiple solutions for the third multiplication, but unique results for the two repeated multiplications and the value of TWENTY. There seemed to be more than ten answers for the third multiplication, but I have only shown five results at the end of my code.

@geoff: I think you are getting multiple solutions because you need to check the “shape” of the intermediate multiplications in the sums. So you need some equivalent of the

match()expressions in my solution.Adding the following constraints to your model will get you down to a single, unique solution:

Also the following two pairs of constraints in your model are equivalent within the pair, so you only need the first one of each pair.

Hi Jim, Yes, your extra constraints work OK and give a single solution, as you state.

A useful programming critique.

At least my answer for TWENTY was still OK – I guess the answer is not affected by the “shape” of the third multiplication?

Re programming these alphametic Enigma puzzles, I have found another type which was difficult in MiniZinc i.e. the type where only one letter is wrong e.g. Enigma 197. The techniques you used in Python for this Enigma don’t seem readily applicable to a MiniZinc solution.

Interested if you think a MiniZinc solution is possible for Enigma 197?

(or maybe is not possible)

@geoff: My method of solving the kind of puzzle you refer too (

Enigma 29,Enigma 197,Enigma 284,Puzzle 76) has been to generate a series of alphametic sums that differ from the given incorrect sum in one place, and then run them all through theSubstitutedSum()solver from theenigma.pylibrary. In the case ofEnigma 197this requires checking 192 different alphametic sums, but fortunately the solver deals with them all in under a second.An alternative would be to use the general alphametic solver, and generate a sum for each position in the original sum, where the symbol at that position is a new alphametic symbol that does not have to take on a different digit value from the other symbols. That way, for

Enigma 197we only require checking 24 different alphametic sums. Unfortunately using theSubstitutedExpression()solver turns out to be slower than checking the 192 sums using theSubstitutedSum()solver.Another way would be to consider partial sums. The given alphametic sum gives no solutions, but we can consider it without the leftmost column, and if that has solutions we can try substituting the symbols for each place in the column. If not we remove another column from the left, and try again. This method would require checking 8 (each column) + 3 (each place in the column) = 11 sums. But I didn’t code this approach up.

But each of these approaches would require a MiniZinc model for each of the sums considered. You can automate their generation using the

minizinc.pylibrary, but the end result will still be quite slow.An approach that uses a single MiniZinc model, is to create a new alphametic sum

abcdefgh + ijkmnpqr = stuvwxyz, with symbols that don’t have to have different digit values (just as well as we have 24 symbols and only 10 digits), but the symbolsdohave to match up with the original incorrect sumexceptin exactlyoneposition.I’ve posted the MiniZinc model as a comment on

Enigma 197.