Fact and Fiction

Thoughts about a funny old world, and what is real, and what is not. Comments are welcome, but please keep them on topic.

Friday, February 09, 2007

Enigma variations

Am I the only one, or has anyone else noticed how a lot of the New Scientist brainteasers (in the Enigma section) appear to have been constructed so that they can be solved by brute force? In fact, brute force makes it very easy to construct a "brain" teaser in the first place, because all you need to do is to describe a largish (but not too large) ensemble of potential solutions (e.g. all possible n-by-n grids of digits), then state a set of conditions that a unique member of the ensemble has to satisfy, then ask the reader to find that unique member, and submit it as their solution to the "brain" teaser.

Enigma 1428 in the most recent New Scientist appears to belong to this category of "brain" teaser. Here it is:

Foursight. Enigma No. 1428

If you place a 1, 2, 3 or 4 in each of the sixteen places in this grid, with no digit repeated in any row or column, then you end up with a “Latin square”. Then you can read eight four-figure numbers in the grid, namely across each of the four rows and down each of the four columns. Your task today is to construct such a Latin square in which those eight numbers are all different, none is a prime, no two are reverses of each other, and:

1st column X 3rd column
2nd row X 3rd row

is greater than 4.

The relatively small size of this problem, and the fact that it looks numerically messy, immediately suggested to me that it was designed on computer, and that the quickest way to get the correct result was a brute force computer attack. I got out my trusty Mathematica and did the following steps (inputs in bold), where I made abolutely no attempt to streamline the code, I generated each input by copying/pasting/modifying earlier inputs, and the goal was to get to the answer as quickly as possible. The code is not really intended to be read except by masochists; it is a special write-only style that I use for problems like this.

How many candidate Latin squares with all digits different in each single row?



Construct all possible single rows.

perms = Permutations[{1, 2, 3, 4}]


Join together in all possible ways to make all possible candidate Latin squares.

perms2 = Flatten[Table[{perms[[i]], perms[[j]], perms[[k]], perms[[l]]}, {i, 24}, {j, 24}, {k, 24}, {l, 24}], 3];


Keep only the ones in which each single column has all digits different. The rows already satisfy this condition.



Keep only the ones in which all 8 rows and columns are different numbers.



Keep only the ones in which none of the 8 rows and columns is prime.



Keep only the ones in which none of the 8 rows and columns is the reverse of another.



Keep only the ones in which col 1 * col 3 / (row 2 * row 3) > 4.



The unique answer.




Post a Comment

<< Home