Home More Samples
```
///////////////////////////////////////////////////////////////////////////////
// Dutch squares
///////////////////////////////////////////////////////////////////////////////
// Enigma 1368 Richard England, New Scientist magazine, November 26, 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.
//
// Please send in the numerical value of the square root of (EEN x VIER x NEGEN)
//
///////////////////////////////////////////////////////////////////////////////
//
// Solve the problem by running the query:
//
//          all DutchSquares(x)
//
///////////////////////////////////////////////////////////////////////////////
//
// Result:
//
// x = 144837
// ___ Solution: 1 ___ [00:00:00] __ [Backtracks: 483] ____
//
// Number of solutions: 1   Number of backtracks: 1158
// Elapsed time: 00:00:00
//
///////////////////////////////////////////////////////////////////////////////

pred DutchSquares(x:>L) iff
arr::[0..]->>L[0..9] & arr = [e,n,v,i,r,g] &
een   = 100*e + 10*e + n & e <> 0 &
vier  = 1000*v + 100*i + 10*e + r & v <> 0 &
negen = 10000*n + 1000*e + 100*g + 10*e + n & n <> 0 &
RtlIsPowerOf2(een) &
RtlIsPowerOf2(vier) &
RtlIsPowerOf2(negen) &
x = RtlSquareRoot(een*vier*negen)

```