So I figured I'd just generalize my solution and write a small app that would solve them for me. I also figured it would give me a chance to use WPF which I enjoy but don't get to use enough it my day job.
Feel free to download it and play around with it. Some features are:
- Solves puzzles
- Allows saving and loading of puzzles
- Allows you to try out your own rules to see how they work (just implement ISudukoRule and add your rule to the rule collection)
- Keeps an up to date 'possible' list for each box, displayed via the tool tip
It uses three main rules and then a backup guess rule. The three rules are:
- If a box can only be one number then put that number in the box.
- If a number only can go one place in a group (row, column, or 3x3 box) then put it in that box.
- If 2 numbers only appear together in 2 boxes in a group then excluded them from going in any other box in that group.
Those 3 rules will solve all but the hardest puzzles, so once those rules stop producing results it falls back to the guess rule which tries to eliminate a value from a box. So it looks for a box with the fewest possible values, picks a value to try and then re-solves. If it solves the puzzle we are done. But if it fails then if we are in an unsolvable state (a box has no possible values). Then we know that the value we picked can't be the right one (proof by contradiction) and we excluded it and go back to the three original rules. Otherwise we guess on a different box.