# 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]

### 4 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)[2] == m and str(xymes)[3] == e and \
str(xymes)[4] == 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.