# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1671: Power engineering

From New Scientist #2837, 5th November 2011 [link]

Read from left to right, the different digits in the number ENIGMA are in descending order, and not necessarily consecutive.

Given that E6 + NI3 + GMA2 = EENNGG, find ENIGMA.

[enigma1671]

### 3 responses to “Enigma 1671: Power engineering”

1. Jim Randell 30 November 2011 at 10:24 pm

A straightforward Python program solves this puzzle in 30ms:

```from enigma import printf

for A in range(0, 5):
for M in range(A+1, 6):
for G in range(M+1, 7):
for I in range(G+1, 8):
for N in range(I+1, 9):
for E in range(N+1, 10):

NI = N*10 + I
GMA = G*100 + M*10 + A
EENNGG = E*110000 + N*1100 + G*11

if not(E**6 + NI**3 + GMA**2 == EENNGG): continue

printf("ENIGMA={E}{N}{I}{G}{M}{A}")
```

Solution: ENIGMA = 876432.

• Jim Randell 31 March 2013 at 11:43 am

Or perhaps a little neater, using itertools.combinations().

```from itertools import combinations
from enigma import irange, printf

for (A, M, G, I, N, E) in combinations(irange(0, 9), 6):
NI = N*10 + I
GMA = G*100 + M*10 + A
EENNGG = E*110000 + N*1100 + G*11

if not(E**6 + NI**3 + GMA**2 == EENNGG): continue

printf("ENIGMA={E}{N}{I}{G}{M}{A}")
```
2. geoffrounce 15 September 2016 at 8:43 pm
```% A solution in MiniZinc
include "globals.mzn";

var 1..9: E;  var 1..9: N;  var 1..9 :I;
var 1..9: G;  var 1..9: M;  var 1..9: A;

constraint alldifferent ([E,N,I,G,M,A]);
constraint decreasing ([E,N,I,G,M,A]);

constraint E*E*E*E*E*E + (N*10+I)*(N*10+I)*(N*10+I) +
(G*100 + M*10 + A)*(G*100 + M*10 + A)
= G + G*10 + N*100 + N*1000 + E*10000 + E*100000;

solve satisfy;

output ["Enigma = ",show(E),show(N),show(I),show(G),
show(M),show(A),"\n"];    % 876432

```