# Sunday Times Teaser 3087 – Hexagonia

*by Nick MacKinnon*

#### Published Sunday November 21 2021 (link)

Hexagonia is a hexagonal republic and is divided into 24 numbered counties, as shown. The counties are to be reorganised into four departments, each composed of six edge-connected counties. No two departments will have the same shape or be reflections of each other, and the president’s residence in Department A will be built on an axis of symmetry of the department. Every sum of the county numbers in a department will be, in the prime minister’s honour, a prime number, and her mansion will be built in the middle of a county in Department B, on an axis of symmetry of the department, and as far as possible from the president’s residence.

In what county will the Prime Minister’s mansion be built?

Now with a speed improvement inspired by Frits.

The program finds eight arrangements of the four Departments but only one of them meets the requirements of the teaser.

Similar

Or use frozenset() instead of tuple(sorted()) as frozensets are hashable as well.

A different approach (not as fast).

First all possible departments are determined (86 in total).

Then this list is reduced to 57 departments as some counties always have to occur with another county.

Out of this 57 departments arrangements of 4 departments are determined so that all counties are present in those 4 departments (resulting in 8 arrangments).