Home More Samples
```
///////////////////////////////////////////////////////////////////////////////
// Not a square
///////////////////////////////////////////////////////////////////////////////
// Enigma 1555 Richard England, New Scientist magazine, July 25, 2009
///////////////////////////////////////////////////////////////////////////////
//
// Fill each of the 12 cells
//
//      +--+--+
//      |  |  |
//   +--+--+--+--+
//   |  |  |  |  |
//   +--+--+--+--+
//   |  |  |  |  |
//   +--+--+--+--+
//      |  |  |
//      +--+--+
//
// with a digit so that the two four-digit numbers that you can read down, the
// two two-digit numbers that you can read down at the sides and the two-digit
// number that you can read across at the bottom are all different perfect
// squares (with no leading zeros). Only the two-digit number that you can read
// across at the top is not a perfect square.
// What is that two-digit number?
//
///////////////////////////////////////////////////////////////////////////////
//
// Solve the problem by running the query:
//
//       all Enigma_1555(x)
//
///////////////////////////////////////////////////////////////////////////////
//
// Results:
//
// x = 71
// ___ Solution: 1 ___ [00:00:00] __ [Backtracks: 429225] ____
//
// Number of solutions: 1   Number of backtracks: 571935
// Elapsed time: 00:00:00
//
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//
// Use the following notation for the 12 unknown digits:
//
//       +---+---+
//       | a | b |
//   +---+---+---+---+
//   | c | d | e | f |
//   +---+---+---+---+
//   | g | h | i | j |
//   +---+---+---+---+
//       | k | l |
//       +---+---+
//
//
pred Enigma_1555(x:>L) iff

// Array of twelve digits, each ranging from 0..9
arr ::[0..]->L[0..9] & arr = [a,b,c,d,e,f,g,h,i,j,k,l] &

// No leading zeros for any of the numbers down or across...
a <> 0 & c <> 0 & g <> 0 & b <> 0 & f <> 0 & k <> 0 &

RtlIsPowerOf2(c*1000+d*100+e*10+f) & // First four-digit number across
RtlIsPowerOf2(g*1000+h*100+i*10+j) & // Second four-digit number across
RtlIsPowerOf2(c*10+g) &              // Two-digit number down at the left side
RtlIsPowerOf2(f*10+j) &              // Two-digit number down at the right side
RtlIsPowerOf2(k*10+l) &              // Two-digit number at the bottom
RtlIsPowerOf2(a*1000+d*100+h*10+k) & // First four-digit number down
RtlIsPowerOf2(b*1000+e*100+i*10+l) & // Second four-digit number down
x = a*10+b &                         // The top two digit number
~RtlIsPowerOf2(x)

```