**From New Scientist #2535, 21st January 2006**

Pussicato’s latest painting is a 6-by-6 array of small squares, and each square contains just one colour. At the gallery I saw a group of six girl students looking at the painting. Each girl selected a different horizontal row and independently wrote down the pattern of colours in her row, from left to right, by simply giving a different number to each colour in her row.

Talking to the girls I found the patterns in the rows were as follows. First, i.e. top, row 121341, second row 112213, third row 123221, fourth row 121222, fifth row 122113, sixth, i.e. bottom, row 122134.

Later, another group of six girls carried out the same process for the vertical columns of the painting. Again I noted the patterns, from top to bottom, but unfortunately I forgot to note which column is which.

The patterns in the columns were as above, in no particular order. Pussicato painted more squares green than any other colour.

How many squares in the painting were green?

[enigma1375]

### Like this:

Like Loading...

*Related*

I found this one quite fun to program a solution for, although once I’d worked out the mechanics of the algorithm it was fairly easy to implement.

This Python 3 program works by starting with a maximal colouring of the grid (all 36 squares different colours), and then groups together squares that must be the same colour by applying the given patterns. The patterns for the rows are straightforward as were told directly which rows correspond to which patterns. For the columns I implemented a recursive solver which tries columns that don’t break the patterns of the rows. It runs in 57ms.

Solution:There are 13 green squares in the painting.There are at least 4 colours (as some of the patterns go up to 4), but we can’t determine the exact colouring of the grid. In the diagram above the 13 green squares are shown, along with 11 red squares and 5 blue squares. But the blue squares could be split into up to three different groups of colours, as indicated by the different shades of blue.

I found this quite an intricate puzzle to code.

My approach was to permute the patterns of columns, and for each permutation collect the items from each row matching each colour in each column. Then group together collections that overlap, checking that 2 colours from a row do not become grouped together.

Finally count the number of cells in each valid grouping found.

It’s slightly slower than Jim’s version, around 100ms