# Enigmatic Code

Programming Enigma Puzzles

## Enigma 244: Enigma, BC

From New Scientist #1391, 5th January 1984 [link]

ENIGMA is exactly divisible by EE, NN, II, GG, MM, AA, BB and CC.

Different letters, as usual, stand consistently for different digits.

What is ENIGMA?

[enigma244]

### 4 responses to “Enigma 244: Enigma, BC”

1. Jim Randell 19 December 2014 at 10:28 am

This Python program runs in 38ms.

```from itertools import combinations
from enigma import multiply, mgcd, divc, divf, irange, split, diff, printf

# ENIGMA must be divisible by 11 and at least seven of 2, 3, 4, 5, 6, 7, 8, 9
# so it has to be divisible by 144 x 11 = 1584
d = mgcd(*(multiply(ds) for ds in combinations((2, 3, 4, 5, 6, 7, 8, 9), 7)))
d *= 11
printf("[divisor={d}]")

# possible digits
digits = set(irange(1, 9))

# look at 6-digit multiples of d
for i in irange(divc(100000, d), divf(999999, d)):
ENIGMA = i * d

# split ENIGMA into digits
ds = split(ENIGMA, int)

# the digits should all be different and non-zero
if len(digits.intersection(ds)) != 6: continue

# and ENIGMA should be divisible by each digit
if any(ENIGMA % x > 0 for x in ds): continue

# BC is two digits from what's left
for BC in combinations(digits.difference(ds), 2):

# and ENIGMA should be divisible by B and C
if any(ENIGMA % x > 0 for x in BC): continue

printf("ENIGMA={ENIGMA} BC={BC}")
```

Solution: ENIGMA = 742896.

2. Naim Uygun 19 December 2014 at 12:38 pm
```#Output: ENIGMA = 742896
from itertools import permutations
#Elements p can not be zero
for p in permutations("987654321",8):
e,n,i,g,m,a,b,c=p
ENIGMA=int("".join((e,n,i,g,m,a)))
L=[int(x) for x in  p]
ok=1
for i in L:
k=11*i
if ENIGMA%k  !=  0:
ok=0
break
if ok==1:
print("ENIGMA =",ENIGMA)
break
```
3. geoffrounce 21 December 2014 at 2:02 pm

Not sure why I get two repeated answers ?

```from itertools import permutations
for p in permutations('987654321',8):
e,n,i,g,m,a,b,c = p
enigma = int(e + n + i + g + m + a)
if enigma % int(e + e) != 0:continue
if enigma % int(n + n) != 0:continue
if enigma % int(i + i) != 0:continue
if enigma % int(g + g) != 0:continue
if enigma % int(m + m) != 0:continue
if enigma % int(a + a) != 0:continue
if enigma % int(b + b) != 0:continue
if enigma % int(c + c) != 0:continue
print('Enigma = ',enigma)
```