I can't play sudoku (too complicated for me), but I wanted to challenge myself with writing a sudoku solver.
After (highly recommended) watching Berkeley AI lecures was time to implement some solutions.
Some "hard" sudoku problem found on the internet.
376
6 9
8 4
9 1
6 9
3 4
7 8
1 9
254
Simple to write Depth First Search cheking all combinations was trivial to write but probably won't finish any problem till sun shine. It exponential growing state space (to power of 9!) grows way too fast. 61 nodes each has 9 values.
Assign first available, check if doesn't violate any constraints and if not put on the fringe. Will find solution in hours. Better than brute force, but still far from perfect.
Each assigment remove inconsitent values in neighbour nodes. Higly depends on the strategy on selecting node to be assiged.
Gives answer after visiting 8 milions of states. On my computer 2 hours.
Gives answer after visiting 15 thousands of states in 12 seconds. Hudge improvement
Like in Forward filtering, but after removing if only one value left assigns it and filters further. With fewest possible values strategy find solution after 540 states in less than 1 second. Impressive. With less favourable strategy find solution after 22 thousands of states in 1 minute.