# Enigmatic Code

Programming Enigma Puzzles

## Enigma 477: Gap ‘n enigma

From New Scientist #1628, 1st September 1988 [link]

In the following long multiplication I’ve replaced digits with letters in some places and left gaps in the rest. Where letters are used, different letters are used for different digits.

That’s all you actually need, but to avoid hours of work I can also tell you that GAP is divisible by 9.

What is the value of IMPINGE?

[enigma477]

### 4 responses to “Enigma 477: Gap ‘n enigma”

1. Jim Randell 3 December 2018 at 8:28 am

We can use the [[ SubstitutedExpression() ]] solver from the enigma.py library to tackle this puzzle. I’ve used lower case letters for the dashes.

The following run file executes in 156ms.

Run: [ @repl.it ]

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

SubstitutedExpression

# upper case symbols are distinct
--distinct="AEGIMNP"

# the main multiplication sum
"{xyz} * {GAP} = {ENIGMA}"

# the intermediate multiplications
"{xyz} * {G} = {abc}"
"{xyz} * {A} = {def}"
"{xyz} * {P} = {ghNi}"

# GAP is a multiple of 9
"GAP % 9 = 0"
```

Solution: IMPINGE = 5285061.

And A=4.

The multiplication sum is: 163 × 648 = 105624.

Although it is not necessary to solve the puzzle, the extra [[ "GAP % 9 = 0" ]] expression saves about 25ms of CPU time.

2. Hugh Casement 3 December 2018 at 9:27 am

Am I alone in thinking that one normally writes the intermediate lines in the reverse order?
I know it makes no difference to the sum, but the way the puzzle is arranged looks odd.

• Jim Randell 3 December 2018 at 10:17 am

Yes. The intermediate totals are in the opposite to order to what I would expect too. Although the positioning in the columns makes it clear which is which, and in some ways presenting the multiples of G, A, P in that order makes sense.

3. Brian Gladman 3 December 2018 at 1:58 pm
```from itertools import permutations

for A, E, G, I, M, N in permutations(range(10), 6):
if G and E and I:
P = -(G + A) % 9
gap = 100 * G + 10 * A + P
enigma = 100000 * E + 10000 * N + 1000 * I + 100 * G + 10 * M + A
q, r = divmod(enigma, gap)
if not r and 100 <= q < 1000:
if 100 < q * G < 1000 and 100 < q * A < 1000 and 1000 < q * P < 10000:
if (P * q // 10) % 10 == N:
impinge = (1000000 * I + 100000 * M + 10000 * P
+ 1000 * I + 100 * N + 10 * G + E)
print(f"IMPINGE = {impinge} ({q} x {gap} = {enigma})")
```

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