### Random Post

### Recent Posts

- Enigma 1101: Disappearing numbers
- Enigma 410: Most right
- Tantalizer 475: League table
- Enigma 1102: The Apathy Party
- Enigma 409: Hands and feet
- Puzzle 68: Football and addition: letters for digits
- Enigma 1103: Brush strokes
- Enigma 408: Royal numbers
- Tantalizer 476: Take your partners
- Enigma 1104: Odd and even squares

### Recent Comments

geoffrounce on Enigma 1313: Triangles | |

Jim Randell on Enigma 1313: Triangles | |

Jim Randell on Enigma 1101: Disappearing… | |

Jim Randell on Enigma 409: Hands and fee… | |

Jim Randell on Enigma 410: Most right |

### Archives

### Categories

- article (11)
- enigma (1,097)
- misc (2)
- project euler (2)
- puzzle (24)
- site news (42)
- tantalizer (25)
- teaser (3)

### Site Stats

- 161,719 hits

Here’s a recursive solution in Python. It runs in 43ms.

Solution:The numbers on the cards on the bottom row are 1, 3, 2, 1.Here is my version, which is also recursive:

In my solution I was originally going to use integers 0 to 15 to represent the cells, and then just use differences to represent the arrows, but I was worried about wraparound at the edges of the grid. So, for instance, the program might try 1R in square 7 (2nd row down, 4th column) to get to square 8 (3rd row down, 1st column), which I don’t think should be allowed. In the end I used (row,column) pairs so this problem doesn’t arise, rather than explicitly code around it.

I rewrote my program to use integers and it gives the same unique solution, so it looks like there are no solutions where this problem arises.

Actually the code to eliminate the wraparounds is probably worth the simplification gained from not using pairs. Here’s my revised Python program.

As you suggest, I should have avoided wraparounds but I was lucky and found that there was only one solution anyway and hence no false ones caused by them. I agree that this is a bit sloppy.

Here it is again with wraparound elimination:

And you can eliminate having to check for any potential wrap arounds by representing the grid by the centre of a 10×4 grid, then the horizontal moves can’t make it out of their own row.

The two middle cells in the top row can readily be deduced, so only 432 permutations are possible for the remaining cells, only 6 of which use all the arrow cards.

A simplified version, representing the cells as numbers 0 to 15

it is a depth-first search used in my algorithm and it is a recursive approach.