### Random Post

### Recent Posts

- Tantalizer 450: Marriage problems
- Enigma 1057: Recycled change
- Enigma 452: Figure out these letters
- Puzzle 46: I lose my specs
- Enigma 1058: A row of colours
- Enigma 451: Double halved
- Tantalizer 451: Death rates
- Enigma 1059: Century break
- Enigma 450: A pentagonal problem
- Puzzle 48: Verse on the island

### Recent Comments

Jim Randell on Tantalizer 450: Marriage … | |

Brian Gladman on Enigma 1057: Recycled cha… | |

Jim Randell on Enigma 1057: Recycled cha… | |

geoffrounce on Enigma 452: Figure out these… | |

Jim Randell on Enigma 452: Figure out these… |

### Archives

### Categories

- article (11)
- enigma (1,183)
- misc (2)
- project euler (2)
- puzzle (46)
- site news (46)
- tantalizer (50)
- teaser (3)

### Site Stats

- 184,975 hits

Advertisements

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