# Enigmatic Code

Programming Enigma Puzzles

## Enigma 253: Sum times

From New Scientist #1400, 8th March 1984 [link]

As usual in this letter-for-digits puzzle each letter stands consistently for a digit, different letters representing different digits. This enigma uses a sum and a times:

ENI + GMA = SUM

ENI × GMA = ??MES

That is enough information to determine what the letters stand for, but if you’d like an extra personal clue.

I is (am?) over twice as big as U.

What is ENIGMA?

[enigma253]

### 5 responses to “Enigma 253: Sum times”

1. Jim Randell 25 January 2015 at 8:10 am

This program uses the [[ `SubstitutedSum()` ]] solver from the enigma.py library to generate solutions to the addition sum, and then checks them against the multiplication sum (and verifies the extra hint). You could easily write a program which uses [[ `itertools.permutations()` ]] to generate candidate solutions instead.

This Python program runs in 91ms.

```from enigma import SubstitutedSum, printf

p = SubstitutedSum(['ENI', 'GMA'], 'SUM')
for s in p.solve():
# check the multiplication sum
(ENI, GMA, MES) = (p.substitute(s, x) for x in ('ENI', 'GMA', 'MES'))
r = str(int(ENI) * int(GMA))
if not(len(r) == 5 and r[-3:] == MES): continue

assert s['I'] > 2 * s['U']

SUM=p.substitute(s, p.result)
printf("ENIGMA={ENI}{GMA} [{ENI} + {GMA} = {SUM}, {ENI} x {GMA} = {r}]")
```

Solution: ENIGMA = 279156.

So the sums are: 279 + 156 = 435 (ENI + GMA = SUM) and 279 × 156 = 43524 (ENI × GMA = SUMES).

• geoffrounce 25 January 2015 at 9:19 am
```from itertools import permutations
for p in permutations('1234567890',8):
e,n,i,g,m,a,s,u = p
if e == '0':continue
if g == '0':continue
if s == '0':continue
eni, gma = int(e + n + i), int(g + m + a)
sum = int(s + u + m)
if eni + gma == sum:
xymes = eni * gma      # x and y are unknown digits
if len(str(xymes))== 5:
if str(xymes) == m and str(xymes) == e and \
str(xymes) == s and i > 2 *  u:
enigma = eni * 1000 + gma
print('ENIGMA = ',enigma)
```
2. Naim Uygun 25 January 2015 at 11:45 am
```
from itertools import permutations

for w in permutations("0123456789",9):
e,n,i,g,m,a,s,u,m=w
if e=='0' : continue

eni=e+n+i
gma=g+m+a

neni=int(eni)
ngma=int(gma)
top=s+u+m
ntop=int(top)
if neni+ngma != ntop : continue

mes=m+e+s
nmes=int(mes)
p=neni*ngma
if p%1000 != nmes : continue

#Answer: ENIGMA= 279156  SUM= 435  PRODUCT= 43524
print("ENIGMA=",eni+gma," SUM=",top," PRODUCT=",p)
break
```
• Jim Randell 25 January 2015 at 3:25 pm

You probably want to check permutations of size 8 rather than 9 (M appears twice in ENI + GMA = SUM), and to be strictly correct you would need to verify that the product is indeed a 5 digit number.

3. geoffrounce 25 January 2018 at 1:47 pm
```% A Solution in MiniZinc
include "globals.mzn";

var 0..9:E;   var 0..9:N;   var 0..9:I;   var 1..9:G;
var 0..9:M;   var 0..9:A;   var 0..9:S;   var 0..9:U;
var 0..9:x;    var 0..9:y;      % x and y are the two ? digits in puzzle

constraint E != 0 /\ G !=0 /\ S != 0 /\ x != 0 /\ I > 2 * U;

constraint all_different ( [E, N, I, G, M, A, S, U]);

var 100..999: ENI = 100*E + 10*N + I;

var 100..999: GMA = 100*G + 10*M + A;

var 100..999: SUM = 100*S + 10*U + M;

var 10000..99999: xyMES = 10000*x + 1000*y + 100*M + 10*E + S;

var 100000..999999: ENIGMA = 100000*E + 10000*N + 1000*I + 100*G + 10*M + A;

constraint ENI + GMA == SUM /\ ENI * GMA == xyMES;

solve satisfy;

output [ "ENIGMA = " ++ show(ENIGMA) ++ "\n"] ;

% ENIGMA = 279156
% ----------
% Finished in 73msec

```

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