19 Replies - 2920 Views - Last Post: 02 July 2013 - 07:40 PM

Sudoku- Your Strategies

Posted 01 July 2013 - 08:54 AM

I came across an interesting article on Sudoku as Graphs, with an application of graph coloring. I haven't studied the Sudoku problem extensively enough to have a good feel for how to solve it. As a graph theorist though, this solution tickled my fancy.

What strategies do you all use when solving Sudoku puzzles algorithmically? What are your thoughts on this problem?

Quote

Enumerate the 81 cells of the Sudoku board with numbers from 81. Then the graph associated with a Sudoku puzzle consists of 81 vertices (one for each cell of the board), together with edges as follows: two vertices are connected by an edge if the cells that they correspond to are in the same column, row or 3x3 box. We have thus represented the Sudoku grid as a graph. With 81 vertices and several hundred edges it would be a big graph if one wanted to draw it, so let us just think about it without attempting to produce a graphical representation. What about the numbers in the cells of the Sudoku puzzle, how do we represent those? Assign each number from 1 to 9 a color. Now color the vertices corresponding to cell that contains a given number in the color of the number.

It is now easy to see that completing a Sudoku puzzle without vioating the Sudoku condition is equivalent to coloring the vertices of the corresponding graph while ensuring that no two adjacent vertices have the same color.

Replies To: Sudoku- Your Strategies

Re: Sudoku- Your Strategies

Posted 01 July 2013 - 09:55 AM

When you say "solve the puzzles algorithmically", are you being redundant, or are you limiting it to some category. In the ladder case I'm not sure what that category would be. I personally always solve sudoku puzzles algorithmically... what other option is there but to just throw numbers in there and get it wrong nearly every time?

I'm sincerely wondering about this as the question. I don't know if you meant what strategies I use when writing code to solve a generic puzzle, as opposed to how I play the game when sitting on the toilet.

Re: Sudoku- Your Strategies

Posted 01 July 2013 - 09:58 AM

I was aiming it at a more Computer Science-y approach. More to the point- if you had to write a program to solve Sudoku puzzles, what approach(es) would you use (hopefully that are better than the BFI method)?

Re: Sudoku- Your Strategies

I've never personally approached solving it from a computer science perspective.

As a first rough start, as I like to go it how I go at things in the real world for the fun of it. I'd start by applying my real world algorithms to it. Making the computer emulate me as a player.

I mostly would take this approach because I like making video-games, and having the computer emulate how a player would do it is kind of important to me so that I can have interesting AI to play against in a game.

I'll have to think about how I'd approach it from a computer science perspective though...

Re: Sudoku- Your Strategies

Posted 01 July 2013 - 11:27 AM

In an empty sudoku, each cell can contain the entire domain {1..9}.

As you add a value to a cell, you remove that value from all other cells sharing row, column, or box.

On in each iteration, you look at empty cells. If their domain is also empty, then the board is invalid. You then look for any cells with a domain size one. That will be your next pick. When only empty cells with domains of greater than one cardinality exist, you have to guess. This would be a branch in your solver.

Re: Sudoku- Your Strategies

Posted 01 July 2013 - 11:31 AM

baavgai- Have you examined the Traveling Salesman problem before? Your solution seems to emulate an adapted Kruskal approach for finding Hamiltonian circuits on a graph. I like it! It also sounds a lot like the graph coloring problem described in that article!

Re: Sudoku- Your Strategies

Posted 01 July 2013 - 11:58 AM

I think what baavgai meant by guessing is not what you would do in reality, however using a computer to solve the Sudoku puzzle it would be more efficient to take the possibilities that can be easily checked. (direct rows and columns) Then when you get to a point that has no direct clues, Guess rather than looking up adjacent 3x3's in the same row (and column) and checking the number to see if its valid for the first 3x3. You would guess and if you hit a snag two or three iterations down the branch, backtrack and try again.

Re: Sudoku- Your Strategies

Posted 01 July 2013 - 01:03 PM

A computer solution could, I guess, do something similar to what I might do, which is to fill-in all the known values. With a computer, it can pass through ALL the numbers 1..9 (eliminating extant values, of course), for ALL empty cells, each time checking the row, column and square. [What would we call this approach? Apart from expensive. Well, it is not that expensive these days ]

As mere mortals, though, we don't do this: we scan the row/column and square, to narrow down to candidate values. We don't check every value in the domain. Can computers replicate this behaviour? Maybe with AI (about which I know nothing..).

Off-topic: It is this visual aspect that computers lack. After sudoko-ing for a while, we begin to recognise patterns; that is, to quickly spot which number is missing from a zone. This zone is an understanding of the 'square-row-column' as a single entity, rather than three separate objects.

Re: Sudoku- Your Strategies

@andrewsw - I don't see why the computer couldn't understand a 'zone' as you put it. You'd have the set of data, which then had sub-sets of data that broke the data up into the various set types you'd want to deal with in which ever organization of sub-sets you'd want.