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 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:
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:
There’s no reason why the puzzles should always be rectangular in shape. Here’s a triangle:
You can specify the shape of the puzzle in a simple text file, like this one.
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 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.
If you want to play around with the code or are just curious then take a look at it at GitHub.
You can find a few more puzzles of varying difficulty, including solutions, here.