Sudoku solver

To give the impression of continuity, here a holiday type project: a sudoku solver. Mainly written for educational purposes and finding out the rules for sudoku solving. There are only four, but it took some time in putting them with some elegance in the code.

The code does not speculate, just fills in the only remaining option after elimination of other values. If all rules are repeatedly applied until no more progress is made, the puzzle is solved, or the user can add a value. The console output conveniently shows the remaining option. Filling in a value in a field with only two remaining options in the text file is the only user interaction. The trick is finding the one field and value that makes the program to completely solve the puzzle.

The only input is a text file with nine lines, each with nine fields. The fields are a digit or a dash. Like:

- - - - - 5 - 2 9
6 3 - - - - - - -
- - - 4 - 8 - - -
- - - - 9 - 5 - 2
- - 2 - 8 - 6 - -
1 - 7 - 3 - - - -
- - - 6 - 1 - - -
- - - - - - - 7 4
5 8 - 2 - - - - -

Currenly the code is in four classes; AutoSudoku, Grid, Score and Cell. The Grid class should be split into a real Grid for just insterting data and Group, which should contain the rule implementations.

  • Sudoku with source version 0.12

    This is the version with functionality moved to Group. Most methods are refactored to one-purpose size.

  • Refactored version

    The solver can be run from the command line with java -jar SudokuSrc.jar sudoku.txt, assuming Java is installed.


    Last updated: 2009-07-29