### Random Post

### Recent Posts

### Recent Comments

Jim Randell on Enigma 402: A DIY puzzle | |

geoffrounce on Puzzle 71: All wrong, all… | |

Jim Randell on Puzzle 71: All wrong, all… | |

geoffrounce on Enigma 1246: Triangle squ… | |

Hugh Casement on Enigma 1110: Dots and lin… |

### Archives

### Categories

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

### Site Stats

- 157,038 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.