On a soduku solver…

Yesterday, when I was on the bus, I got pulled into a sudoku. Then I started wondering how a machine could be programmed to solve these puzzles.

Note: For the rest of this post:

  • A square is the un-devidable unit containing 1 number
  • A section is a 3×3 grid of squares
  • A column is a 10 square vertical strip
  • A row is a 10 square horizontal strip
  • A board is the 9×9 sudoku board

There a few simple rules that go into solving these puzzles. Namely :

  • What are the possible values for this square (based on row, column and section)
  • What are the possible places for this number (in this section)

The two questions aren’t identical, since a numbers position can be influenced by the positions of numbers in other columns or rows that share the section.

The first question comes down to :

  1. Take the ensemble of possible numbers
  2. Remove all that are already in the current row
  3. Remove all that are already in the current column
  4. Remove all that are already in the current section
  5. if there is only one left, put it in the square
  6. lather
  7. rinse
  8. repeat

The second question comes down to:

For each number not entered in each section

  1. Check for number in the rows that pass through this section, eliminate the squares that belong to them if found
  2. Check for number in the columns that pass through this section, eliminate the squares that belong to them if found
  3. if only one square is left, put the number in it
  4. profit

OK, mabey that one’s a bit vague, I’ll try to make it clearer with a drawing

Example of a row and column problem

Example of a row and column problem

In the above image, concentrate on the bottom middle section. If you look, you’ll notice that there are 4s in the top 2 rows of this section, we can conclude that our 4 must be on the bottom row. We also notice that there is a 4 in the left most column of this section, which only leaves the bottom middle square as a possibility for this 4.

By combining the 2 rules stated above, we should be able to solve any sudoku puzzle.

Any how, that’s all for now. Proof by code will be comeing in an update.

This entry was posted in english, personnel, programming and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>