NavMenu

Saturday, September 4, 2010

Sudoku Solver Progress Update

Today I finally completed the SolverEngine for handling Easy to Medium level boards.  It solves each within 54 msecs.  Of course that execution time could be improved, but I'm not concerned about that right now.

As for Hard to Super Challenger level boards, well it solves a portion of them and then is unable to proceed.  I need to now add on to the SolverEngine algorithms.  I know what I have to do in process; I just have to translate that into actual C# code.

I'm amazed at what I've learned so far just in this one project.  Things like:

  1. Don't use structs unless it represents one item and is less than 16 bytes.  Otherwise you end up boxing and unboxing, which really kills performance and adds to the overhead.  Plus properties look like methods, which just seems odd to me. That was my first rewrite.  I have much more to learn about structs.
  2. Refactor as much as you can.  If you use it more than once, then refactor it.  It saves errors, reduces code, and keeps you sane when you change one but forget to do the others.
  3. Use base class for those common properties and methods that shared amongst classes.  Why I hadn't implemented this in the beginning is beyond me.  Instead at first I repeated properties and methods in the parent grid class (i.e. Row, Column, and Quad on the Sudoku board) and in the child sector class (i.e. a sector being 3 tiles).  Then I finally got smart and refactored it into a base class.
  4. using statement:  So much more concise and readable than having to .Close or .Finalize a resource.  I even got to implement IDisposable and Dispose().
  5. foreach Don't use for ArrayLists that may change while in iteration.  Use a for, do, or while.
There are many other things that I've learned along the way, but those are the main ones that come to mind.

Time to hit Phase 2.  I'll keep you posted.

kick it on DotNetKicks.com

Shout it

No comments:

Post a Comment

About

My photo
Welcome to my blog! This blog is about my journey to become a Master .NET coder and teacher.

Followers