### Introduction

A few years ago I wrote about Sudoku-like puzzles involving siteswaps. Back then I used Prolog with CLP/FD to generate a few small puzzles. The use of Prolog had the unfortunate side-effect that it was rather hard to use the generator on ones own machine. Due to popular demand I’ve re-written the generator on a more popular platform and in the process added a somewhat usable command-line interface and a few features.

### Download and instructions

The application can be downloaded from GitHub. For instructions, read the README file.

### New features

#### Bigger puzzles

The new generator can produce arbitrarily large puzzles, given enough time. In practice, the limit seems to be at around 9×10. Try to solve this one:

. | . | 4 | 2 | . | 6 | 3 | 5 | . | . |

. | 6 | . | 5 | . | . | . | 5 | . | 5 |

. | . | . | . | . | . | . | 5 | . | . |

6 | . | . | . | 4 | . | 5 | 6 | 4 | . |

7 | . | . | 3 | . | 6 | . | . | . | . |

. | . | . | 5 | . | 4 | . | . | . | 7 |

. | . | . | 8 | . | 2 | 8 | 6 | . | 1 |

6 | 4 | . | . | . | 5 | . | 4 | . | . |

. | 4 | . | . | . | 6 | . | . | . | . |

#### Allowed throws

The old generator would always use throws 1 to 9. Now the range is configurable. The more throws you allow, the higher the number of possible solutions, which means that the puzzle must have less unknown elements to be still uniquely solvable. The more you restrict the range of throws, however, the more unknowns the puzzle can take. This one, for example, only allows throws 1 to 5:

. | . | . | . | . | 5 | . |

. | . | . | . | . | . | . |

. | . | . | . | . | . | 1 |

. | . | . | . | . | 1 | . |

2 | . | . | . | . | . | . |

. | 4 | . | . | . | . | . |

#### Arbitrary shapes

There’s no reason why the puzzles should always be rectangular in shape. Here’s a triangle:

. | ||||||||

1 | . | |||||||

1 | 1 | . | ||||||

. | 5 | 1 | 2 | |||||

. | 3 | . | . | 2 | ||||

1 | . | 2 | 5 | . | 4 | |||

. | . | . | . | 3 | . | . | ||

. | . | . | . | . | . | 9 | . | |

. | . | 7 | . | . | . | 1 | 7 | 4 |

You can specify the shape of the puzzle in a simple text file, like this one.

#### Simple rules

The rules for the old generator required that no two siteswaps in the puzzle be the same, which included all the rotations. Many people found this confusing and stumbled over it, so I removed the restriction by default. The old rules are still accessible through a command-line option.

### The Implementation

The new generator is written in Clojure, using the JaCoP finite domain constraint solver to do the heavy lifting. One of the nice features of JaCoP is that the order in which it goes through the range of a variable is configurable, including a random option. Whereas in the old generator I had to pre-assign random values to a few of the elements to get a random puzzle, with JaCoP I can just specify the constraints for the puzzle and then let it generate a random one.

The second step in puzzle generation is the introduction of unknowns. In the new generator, the user has to specify how many unknowns they want in the puzzle. The generator then removes a random subset of that size from the puzzle and checks if it’s still uniquely solvable. The higher the number of unknowns, the smaller the chance that this is the case, meaning that the search will take longer or might indeed never end. I haven’t been able to find a 2×3 puzzle (with throws 1 to 9 and complex rules) with more than 3 unknowns, for example.

### The Code

If you want to play around with the code or are just curious then take a look at it at GitHub.

### More puzzles

You can find a few more puzzles of varying difficulty, including solutions, here.