# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1648: Enigmarred

From New Scientist #2814, 28th May 2011 [link]

Below I have listed seven numbers, but I have coded them by consistently replacing digits with letters, with different letters used for different digits:

```CINEMA
ECZEMA
EMMA
ENEMA
ENIGMA
MAMMA
STIGMA```

All but one of the seven numbers is divisible by 9.

Which word represents the number which is not divisible by 9?

[enigma1648]

### 3 responses to “Enigma 1648: Enigmarred”

1. Jim Randell 6 December 2011 at 6:30 pm

The following Python code runs in 49ms.

```from itertools import permutations
from enigma import printf

# how many things in the list are not multiples of nine
def n9(*s):
return len(filter(lambda n: n % 9 > 0, s))

d = set(range(10))
for (A, E, M) in permutations(d, 3):
if 0 in (E, M): continue
EMMA = E * 1000 + M * 110 + A
MAMMA = M * 10110 + A * 1001
if n9(EMMA, MAMMA) > 1: continue

d1 = d.difference([A, E, M])
EMA = 100 * E + 10 * M + A
for N in d1:
NEMA = N * 1000 + EMA
ENEMA = E * 10000 + NEMA
if n9(EMMA, MAMMA, ENEMA) > 1: continue

d2 = d1.difference([N])
for (C, I) in permutations(d2, 2):
if C == 0: continue
CINEMA = C * 100000 + I * 10000 + NEMA
if n9(EMMA, MAMMA, ENEMA, CINEMA) > 1: continue

d3 = d2.difference([C, I])
for Z in d3:
ECZEMA = E * 100000 + C * 10000 + Z * 1000 + EMA
if n9(EMMA, MAMMA, ENEMA, CINEMA, ECZEMA) > 1: continue

d4 = d3.difference([Z])
for G in d4:
IGMA = I * 1000 + G * 100 + M * 10 + A
ENIGMA = E * 100000 + N * 10000 + IGMA
if n9(EMMA, MAMMA, ENEMA, CINEMA, ECZEMA, ENIGMA) > 1: continue

d5 = d4.difference([G])
for (S, T) in permutations(d5, 2):
if S == 0: continue
STIGMA = S * 100000 + T * 10000 + IGMA
if n9(EMMA, MAMMA, ENEMA, CINEMA, ECZEMA, ENIGMA, STIGMA) != 1: continue

s = (EMMA, MAMMA, ENEMA, CINEMA, ECZEMA, ENIGMA, STIGMA)
i = filter(lambda i: s[i] % 9 > 0, range(len(s)))
n = ('EMMA', 'MAMMA', 'ENEMA', 'CINEMA', 'ECZEMA', 'ENIGMA', 'STIGMA')[i[0]]
printf("{n} {s}")
```

Solution: ENEMA is not divisible by 9.

There are 12 different ways of assigning digits to the letters, but in all cases ENEMA is the only number not divisible by 9.

Here are the 12 assignments:

A=6 C=9 E=2 G=0 I=1 M=5 N=4 S=7 T=8 Z=3
A=6 C=9 E=2 G=0 I=1 M=5 N=4 S=8 T=7 Z=3
A=3 C=9 E=4 G=0 I=2 M=1 N=8 S=5 T=7 Z=6
A=3 C=9 E=4 G=0 I=2 M=1 N=8 S=7 T=5 Z=6
A=6 C=9 E=8 G=0 I=4 M=2 N=7 S=1 T=5 Z=3
A=6 C=9 E=8 G=0 I=4 M=2 N=7 S=5 T=1 Z=3
A=3 C=9 E=1 G=0 I=5 M=7 N=2 S=4 T=8 Z=6
A=3 C=9 E=1 G=0 I=5 M=7 N=2 S=8 T=4 Z=6
A=6 C=9 E=5 G=0 I=7 M=8 N=1 S=2 T=4 Z=3
A=6 C=9 E=5 G=0 I=7 M=8 N=1 S=4 T=2 Z=3
A=3 C=9 E=7 G=0 I=8 M=4 N=5 S=1 T=2 Z=6
A=3 C=9 E=7 G=0 I=8 M=4 N=5 S=2 T=1 Z=6

• Jim Randell 7 August 2017 at 10:49 am

We can use the SubstitutedExpression() solver from the enigma.py library to find the solution to the puzzle and output the list of numbers and assignments neatly using a short run file. Execution time however is 2.5s (using PyPy).

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

SubstitutedExpression
--template="1. CINEMA  2. ECZEMA  3. EMMA  4. ENEMA  5. ENIGMA  6. MAMMA  7. STIGMA"
--answer="tuple(i for (i, x) in enumerate([CINEMA, ECZEMA, EMMA, ENEMA, ENIGMA, MAMMA, STIGMA], start=1) if x % 9 > 0)"

"sum(x % 9 > 0 for x in [CINEMA, ECZEMA, EMMA, ENEMA, ENIGMA, MAMMA, STIGMA]) == 1"
```
2. geoffrounce 26 April 2018 at 9:16 pm
```% A Solution in MiniZinc
include "globals.mzn";

var 0..9 :C; var 0..9: I; var 0..9: N; var 0..9: E;
var 0..9: M; var 0..9: A; var 0..9: Z; var 0..9: S;
var 0..9: T; var 0..9: G;

% Leading digits cannot be zero
constraint C != 0 /\ E != 0 /\ M != 0 /\ S != 0;

constraint all_different ( [C, I, N, E, M, A, Z, S, T, G] );

% Numbers are divisible by 9 if the sum of their digits is divisible by 9
constraint  sum ( [
(C + I + N + E + M + A) mod 9 == 0,
(E + C + Z + E + M + A) mod 9 == 0,
(E + N + I + G + M + A) mod 9 == 0,
(S + T + I + G + M + A) mod 9 == 0,
(E + M + M + A) mod 9 = 0,
(E + N + E + M +  A) mod 9 == 0,
(M + A + M + M + A) mod 9 == 0
]) == 6;

solve satisfy;

output [ "  CINEMA  " ++ "has remainder " ++ show ( (C+I+N+E+M+A) mod 9) ]
++ [ "\n  ECZEMA  " ++  "has remainder " ++ show  ((E+C+Z+E+M+A) mod 9)]
++ [ "\n  ENIGMA  " ++ "has remainder " ++ show ((E+N+I+G+M+A) mod 9) ]
++ [ "\n  STIGMA  " ++ "has remainder " ++ show ((S+T+I+G+M+A) mod 9)]
++ [ "\n  EMMA  " ++ "has remainder " ++ show ((E+M+M+A) mod 9)]
++ [ "\n  ENEMA  " ++ "has remainder " ++ show ((E+N+E+M+A) mod 9) ]
++ [ "\n  MAMMA  " ++ "has remainder " ++ show ((M+A+M+M+A) mod 9) ];

% Multiple solutions all give ENEMA with a remainder > 0 when divided by 9.

```

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