# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1130: Time and again

From New Scientist #2286, 14th April 2001 [link]

To practise my long multiplication I have taken two three-figure numbers (using six different digits between them) and multiplied the first by the second. Then, as a check, I multiplied the second by the first. The results are shown with dashes for all non-zero digits: What were the two three figure numbers?

[enigma1130]

### 2 responses to “Enigma 1130: Time and again”

1. Jim Randell 30 January 2017 at 7:43 am

The intermediate multiplications in the sums are given in the opposite order (from top to bottom) than I would normally write them, and also I would normally use blanks to pad the right hand side, rather then zeros. But the form of the sum is clear.

I used the general Alphametic solver [[ `SubstitutedExpression()` ]] from the enigma.py library to consider the multiplications (ABC × DEF) and (DEF × ABC). The digits ABCDEF are used for the two three-figure numbers and are all different, I use the lower-case letters abcdefghijklmnopqrstuvw to stand for the remaining non-zero digits, with Z standing for zero.

This is the run file, which executes in 94.6ms.

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

# 94.62ms (9.56ms internal)

# use the alphametic solver
SubstitutedExpression

# solver parameters
--symbols=ABCDEFabcdefghijklmnopqrstuvwZ
--distinct=ABCDEF
--assign=Z,0
--digits=1-9

# expressions to solve
"ABC * DEF = abcdef"
"D * ABC = gZhi"
"E * ABC = jkl"
"F * ABC = mnZo"
"A * DEF = pZqZ"
"B * DEF = rst"
"C * DEF = uvw"
```

Solution: The three-figure numbers are 534 and 216.

Here are the two multiplications in full: 2. GeoffR 4 August 2019 at 2:10 pm
```% A Solution in MiniZinc
include "globals.mzn";

% the two three digit numbers
var 0..9:a; var 0..9:b; var 0..9:c;
var 0..9:d; var 0..9:e; var 0..9:f;

constraint all_different ( [a,  b, c, d, e, f])
/\ a > 0 /\ d > 0;

% the two three-figure numbers are abc and def
var 100..999: abc = 100 * a + 10 * b + c;
var 100..999: def = 100 * d + 10 * e + f;

% 1st sum - multipication results
var 100000..999999: line1 = d * 100 * abc;
var 1000..9999: line2 = e * 10 * abc;
var 1000..9999: line3 = f * abc;

% 2nd sum - multipication results
var 100000..999999: line4 = a * 100 * def;
var 1000..9999: line5 = b * 10 * def;
var 100..999: line6 = c * def;

% 1st sum - check zero positions
constraint line1 div 10000 mod 10 == 0;
constraint line1 div 10 mod 10 == 0;
constraint line1 mod 10 == 0;
constraint line2 mod 10 == 0;
constraint line3 div 10 mod 10 == 0;

% 2nd sum - check zero positions
constraint line4 div 10000 mod 10 == 0;
constraint line4 div 100 mod 10 == 0;
constraint line4 div 10 mod 10 == 0;
constraint line4 mod 10 == 0;
constraint line5 mod 10 == 0;

solve satisfy;

output [ "Sum is " ++ show(abc) ++ " * " ++ show(def)
++ " = " ++ show(abc * def)];
% Sum is 534 * 216 = 115344

```

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