## Sudoku Applet

Over the last two evenings I created this, a Sudoku Java applet.

git clone git://github.com/skeeto/Sudoku.git

Play the applet: SudokuApplet

The hardest part was creating and implementing the algorithm for generating new Sudokus. The first step to writing any Sudoku generator is to write a Sudoku solver. Use it to solve an empty board in a random order, then back off while maintaining a single solution. For a proper Sudoku, this has to be done symmetrically leaving no more than 32 givens.

I didn't work out a great way to determine the difficulty of a particular puzzle. The proper way would probably be to solve it a few different ways and measure the number of steps taken. Right now I'm controlling difficulty by adjusting the number of givens: 24 (hard), 28 (medium), and 32 (easy). Harder puzzles take longer to generate because the search-space is less dense, due to the strict constraints.

Have a comment on this article? Start a discussion in my public inbox by sending an email to ~skeeto/public-inbox@lists.sr.ht [mailing list etiquette] , or see existing discussions.

This post has archived comments.