2013

Sudoku Solver

A desktop Sudoku solver in Java and SWT, solving by recursive backtracking.

  • Java
  • Eclipse SWT

The ancestor of the Sudoku game elsewhere on this site. Where that one helps a human play, this one simply solves: a recursive backtracking algorithm that takes the next empty square, tries each legal value in turn, and unwinds when it reaches a contradiction.

Written against Eclipse SWT, which wraps the operating system’s own widgets, so it cannot be made to run in a browser by any amount of effort — there is nothing underneath it to wrap.

The algorithm is live, though. It has been rewritten in TypeScript and built into the Sudoku game as a solve mode: press the button and watch it work. The default is this same approach — next empty square, try, recurse, unwind — with a smarter most-constrained-square-first strategy available alongside it for comparison. On the hardest puzzle there the two differ by a factor of 270, and you can watch both take the same ten seconds.

Your own entries are treated as fixed, so if you have put something in the wrong place the search exhausts and says so rather than quietly correcting you.