# Sunday Times Teaser 2803 – Easy as ABC

*by Danny Roth*

#### Published: 12 June 2016 (link)

George and Martha have replaced the digits 0 to 9 by the letters A to J in some order. George then noted a neat product, namely:

**AB** x **CDE** = **FGHIJ**

Then Martha noted a neat sum, namely

**AB** + **CD** + **EF** + **GH** + **IJ** = **CCC**

What, in order, are the values of the letters **A** to **J**?

7 Comments
Leave one →

Here is a general solution for alphametics. It is very slow but it can be used to solve a set of alphametic equations such as those in this teaser.

It provides an answer for this teaser:

in 30 seconds which compares with 110 milliseconds for the program above.

We can also use the AlphaSum solver to solve the addition sum and then use its results with the multiplication sum:

which runs in 2.5 seconds. It is slower than solving the multiplication sum first because the addition sum has many more solutions than the multiplication sum.

Here are two solutions that use the SubstitutedSum() solver from the

enigma.pylibrary [ https://www.magwag.plus.com/jim/enigma.html ].The first is short, but not very quick (as there are lots of solutions to the addition sum because the summands can appear in any order). It solves the addition sum and then checks the values also work in the multiplication sum.

The second starts by solving the multiplication sum (which has fewer solutions), and checks if the values work in the addition sum. It’s a bit longer, but a lot quicker.

Hi Jim,

I did not think of doing the teaser this way but I did contemplate adding a second array to my sum solver that contains the factors by which the corresponding values in the sum are multiplied.

My first thought was that this would be a constant set on input but I contemplated converting the sum solver into a product solver by allowing this array to participate in the substitution process.

But I then realised that a lot of substituted product teasers involve constraints on partial products so we would need a full scale product solver.

Given you have a sum solver and a division solver in enigma.py, this is a gap that I will leave you fill as I don’t much like alphametics anyway!

I’ve added a generic Alphametic solver to the

enigma.pylibrary, which allows problems like this to be solved directly from the command line:On my machine this runs in 469ms, compared with 155ms for the second program I gave above.

I’ve written an article showing how to use it to solve several similar puzzles in only a few seconds. It’s available at [ https://enigmaticcode.wordpress.com/2016/06/22/solving-alphametics-with-python/ ].

It is possible to combine the two equations into a single expression,

‘(AB*CDE == FGHIJ) & (AB + CD + EF + GH + IJ == CCC)’,

then test the expression using Raymond Hettinger’s code.