# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1368: Dutch squares

From New Scientist #2527, 26th November 2005

Een, vier and negen are the Dutch for 1, 4 and 9; so it is appropriate that I can make the following statement:

EEN, VIER and NEGEN are perfect squares.

In this statement digits have been consistently replaced by capital letters, different letters being used for different digits. No number starts with a zero.

Find the numerical value of the square root of (EEN × VIER × NEGEN).

[enigma1368]

### 3 responses to “Enigma 1368: Dutch squares”

1. Jim Randell 1 December 2013 at 7:58 am

This Python program runs in 35ms.

```from itertools import permutations
from enigma import irange, is_square, printf

digits = set('0123456789')

# find 3-digit squares matching EEN
for i in irange(10, 31):
EEN = str(i * i)
(E, E2, N) = EEN
if not(E == E2 and E != N): continue

# now consider values for NEGEN
d1 = digits.difference([E, N])
for G in d1:
NEGEN = int(N + E + G + E + N)
j = is_square(NEGEN)
if j is None: continue

# and VIER
d2 = d1.difference([G])
for (V, I, R) in permutations(d2, 3):
VIER = int(V + I + E + R)
k = is_square(VIER)
if k is None: continue

s = i * j * k

printf("s={s} [EEN={EEN} NEGEN={NEGEN} VIER={VIER}]")
```

Solution: The square root of (EEN × VIER × NEGEN) is 144837

• Jim Randell 10 February 2018 at 11:31 am

Here is a solution using the [[ SubstitutedExpression() ]] solver from the enigma.py library. It executes in 93ms.

Run: [ @repl.it ]

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

SubstitutedExpression

"is_square(EEN)"
"is_square(VIER)"
"is_square(NEGEN)"
```
2. geoffrounce 30 November 2017 at 3:25 pm
```% A MiniZinc solution
include "globals.mzn";

var 0..9:E;  var 0..9:N;  var 0..9:V;  var 0..9:I;  var 0..9:R;  var 0..9:G;

constraint E != 0 /\ V != 0 /\ N != 0 /\ all_different( [E, N, V, I, R, G] );

predicate is_square(var int: y) = exists(z in 1..ceil(sqrt(int2float(ub(y)))))
(z*z = y );

constraint is_square(100*E + 10*E + N ) /\ is_square(1000*V + 100*I + 10*E + R)
/\ is_square(10000*N + 1000*E + 100*G + 10*E + N);

solve satisfy;

output ["Square root of (EEN * VIER × NEGEN) is " ++ show( round( fix( sqrt(
(100*E + 10*E + N) * (1000*V + 100*I + 10*E + R) * (10000*N + 1000*E + 100*G
+ 10*E + N) ) ) ) ) ];

% Square root of (EEN * VIER × NEGEN) is 144837
% ----------
% Finished in 61msec
```