Over the Christmas and New Year holiday, I got into playing “Ball Sort Puzzle” – a simple concept for a puzzle game with straightforward rules, but which can be surprisingly tricky to solve.
I thought it was an interesting problem to think about how to write a program to solve these puzzles – so I wrote one in Python. It’s a pretty naive recursive backtracking solver (I only spent a couple of hours writing it) – and it could be more efficient – but nevertheless it works and it’s available on Github here.
I also included a script to generate random puzzles of any size. Not all of them have a solution (particularly as they get bigger) but it’s surprising how many of the random puzzles can be solved.