### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,525)
- enigma-book-1982 (71)
- misc (5)
- project euler (2)
- puzzle (90)
- puzzle# (129)
- site news (70)
- tantalizer (170)
- teaser (7)
- today (1)

### Site Stats

- 287,427 hits

Programming Enigma Puzzles

20 September 2021

Posted by on **From New Scientist #2031, 25th May 1996** [link]

We spent our holiday on the oddly-shaped island of Hexonia. One day, we drove around the coast road which was in the form of a hexagon with each angle 120°. I remember noticing that each straight was a different perfect square whole number of kilometres and that the complete circuit was less than 500 kilometres.

How far did we drive?

[enigma876]

%d bloggers like this:

This Python program travels the perimeter of the island, using

isometricco-ordinates (where the axes are 60° apart).In order to eliminate duplicate solutions we consider the longest side first, and then the second side should be longer than the last side (otherwise we could start at any vertex and travel in either direction, giving 12 times the number of distinct solutions).

It runs in 274ms.

Run:[ @replit ]Solution:The total distance is 420 km.The sides of the island have the following lengths (in km): 169, 16, 49, 121, 64, 1.

Here is a diagram of the island:

I’m not sure we need isometric coordinates. The net distances south and east must both be zero:

b + c – e – f = 0, 2(a – d) + b – c – e + f = 0.

If those are six different square numbers with sum less than 500 there is only one sequence, or its cyclic permutations clockwise or anticlockwise. To eliminate most of those duplicate solutions I started with the smallest.

Using Hugh’s idea of horizontal and vertical distances, I calculated these distances in terms of the sides of the hexagon, using cos(60) for the horizontal distances and sin(60) for the vertical distances.

Fot the horizontal distances, I got:

S6/2 + S1 + S2/2 = S3/2 + S4 + S5/2

and, for the vertical distances:

S2 * sqrt(3)/2 + S3 * sqrt(3)/2 = S5 * sqrt(3)/2 + S6 * sqrt(3)/2

These equations translate to the two constraints in the code after the all sides square constraint.