Wednesday, December 31, 2008

Sudoku Helper

I enjoy doing Sudoku puzzles to kill time, but after do a couple of them they get pretty monotonous, some are harder than others but all are solvable given some time.


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.

Wednesday, December 3, 2008

Macros in Hint Paths

I am working on building a binary publishing system at my work.  While implementing it I ran into what I thought might be a snag.  I wanted to switch a project from having a project reference to another project to be a binary reference.  But I wanted that binary reference to change depending on which configuration (Debug/Release) I was in.  This seems like a pretty standard thing to do.  You want the binary reference to come from bin/release in release mode and bin/debug in debug mode.

The VS GUI gives no indication that this is possible, you pick a file location for a dll and you are done.  Luckily VS is smart enough to interpolate macros in the hint path for the reference.  So you can make the hint path be some thing like ../bin/$(Configuration)/foo.dll and you will get the behavior you want.  But you need to crack open the .csproj file in a text editor to do this.

One the one hand it is really nice that VS is smart enough to enable this scenario.  On the other hand it would be nice if there was a way to do this via the GUI.