### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,158)
- misc (2)
- project euler (2)
- puzzle (40)
- site news (44)
- tantalizer (42)
- teaser (3)

### Site Stats

- 178,002 hits

Advertisements

Programming Enigma Puzzles

24 March 2017

Posted by on **From New Scientist #1537, 11th December 1986** [link]

In the following division sum, some of the digits are missing and some are replaced by letters. The same letter stands for the same digit wherever it appears. The digits in the answer are all different.

Find the correct sum.

[enigma389]

Advertisements

%d bloggers like this:

We can use the

SubstitutedDivision()solver from theenigma.pylibrary to solve this in 436ms.However, we can get a faster solution (although with more typing) by using the

SubstitutedExpression()solver.This run file translates the lower case letters in the original sum to upper case and adds additional upper case letters for the dashes. The complete run time is 147ms.

Solution:The correct sum is 305283 ÷ 33 = 9251.Even without the additional condition that all the digits in the result are different there is only one solution.

I used lowercase versions of the letters you used in my solution and got the same answer

ie 9251 X 33 = 305283 in 84 msec.

The programme was a bit long in MiniZinc, but I wanted to try a division alphametic in MiniZinc

I used ‘FG’ (lowercase) in the multiplications (as your statement of the puzzle) but noticed you say ‘EF’ in the solver for the divisor? Anyway, I get the same answer.

@geoff: Thanks for pointing out the EF / FG mix-up. I renamed some of the symbols I used before posting my code, but I must have missed changing them in the multiples. Fortunately it turns out that E, F and G all stand for 3, so it didn’t affect the result of the program, but I’ve sorted it out now.

I’d been considering writing code to automatically turn these problems into expressions that can be fed directly into the

SubstitutedExpression()solver without manual intervention. So maybe it’s time to look at that again.This puzzle has led me to make the “distinct” parameter for the

SubstitutedExpression()solver more flexible.This means we can now specify multiple sets of symbols, and the values of the symbols in each set have to be distinct from the values of the other symbols

in that set, but may be the same as the value of symbols in different sets.This removes the need for the

"is_pairwise_distinct(H, I, J, L)"expression (line 38) in my solution using theSubstitutedExpression()solver. Instead we can just specify the “distinct” parameter as--distinct="DKRT,HIJL"at line 20. The rest of the file remains the same.This functionality is available in

enigma.pyfrom version 2017-03-24.The new implementation of the

SubstitutedDivision()solver in theenigma.pylibrary is derived fromSubstitutedExpression()so we can use the same technique to require the digits of the result to be distinct, but we don’t need to specify symbols for the rest of the sum.Here’s a run-file that uses the new

SubstitutedDivision()solver. It executes in 179ms.