### Random Post

### Recent Posts

- Enigma 1065: Cute cubes
- Enigma 444: Rows and rows
- Puzzle 50: Football and addition
- Enigma 1066: Members of the clubs
- Enigma 443: The bells they are a-changing
- Tantalizer 455: Ballistico
- Tantalizer 456: Square deal
- Enigma 1067: Bye!
- Enigma 442b: Oh yes I did! Oh no you didn’t!
- Puzzle 51: A multiplication

### Recent Comments

Brian Gladman on Enigma 1065: Cute cubes | |

Jim Randell on Enigma 1065: Cute cubes | |

geoffrounce on Enigma 444: Rows and rows | |

Jim Randell on Enigma 444: Rows and rows | |

geoffrounce on Enigma 1611: Three sister… |

### Archives

### Categories

- article (11)
- enigma (1,167)
- misc (2)
- project euler (2)
- puzzle (42)
- site news (45)
- tantalizer (45)
- teaser (3)

### Site Stats

- 180,599 hits

Advertisements

I considered the nodes to be laid out on an triangular gird (with 60° between the axes). I represent the nodes by an integer. The point (x, y) is represented by (x + N × y) for sufficiently large N that we don’t suffer from “wraparound” issues. The program uses N=100, which is sufficiently large for the relatively small shapes of the problem, and translates the point (x, y) to the integer y0x, which is easy to decode (for points with single digit co-ordinates, which is all that is required for this problem).

Moves are then also represented by integers, by calculating the difference between the destination node and the source node. For example moving parallel to the x-axis: (x, y) -> (x+1, y) is represented by +1, (x, y) -> (x-1, y) is represented by -1. Moving parallel to the y-axis is represented by +100 and -100, and moving along the x+y=n direction is represented by +99 and -99. These represent the six possible moves from each point (providing there is a destination point in the required direction). Moves along the same axis have the same magnitude (absolute value).

Then a straightforward search gives the solution. The program attempts to start a path from each node, which is a bit wasteful, but if the path can be closed it is returned immediately, and so, in this case, only paths from the first point will be considered. However, if there is no closed path then the program will exhaustively try to construct all possible paths from each node, and this number of candidate paths could be reduced by symmetry, but for the relatively small shapes given in the puzzle it is not really a problem.

This Python 3 program finds a solution for (a) in 50ms, for (b) in 5.1s and for (c) in 2.0s.

Solution:The hexagon (b) can be wiggled but not using a closed path. The hexagon (c) can be wiggled using a closed path.Here are the paths my program finds, but there are other solutions: