Like HowStuffWorks on Facebook!

How Sudoku Works


If you've been in a book store in the last six months -- or an airport, waiting room or college lecture class -- you've probably seen someone staring at a sudoku. Given its popularity, one might think it's some new type of porn. But no, it's just a puzzle. It's a widespread, logic-based fad of a puzzle that is simple enough to suck you in and difficult enough to keep you hooked.

In this article, we'll find out what a sudoku puzzle entails, how to go about solving one and where the concept originated (hint: It's not Japan. Let's get started.

Sudoku Basics

Sudoku (or su doku) is a game of numbers -- specifically, the numbers 1 through 9 -- but it really isn't about math. It's about logic. Instead of 1 through 9, you could use the first nine letters of the alphabet or a set of nine symbols, and it would be the same game.

The basis of sudoku is a nine-by-nine grid. You've got three sections to think about: rows, columns and boxes.

The goal of sudoku is to fill each nine-square row, each nine-square column and each nine-square box with the numbers 1 through 9, with each number used once and only once in each section. It's the interaction between the rows, columns and boxes that tells you where the numbers need to go. So if you were to start with a blank grid and fill in the numbers for row 1, column 2 and box 4 according to the sudoku rules, it might look something like this:

Of course, starting with a blank grid wouldn't make it much of a challenge. A sudoku puzzle already has some of the numbers filled in, and it's your job to figure out where the rest of the numbers go. Here's an example of a real sudoku puzzle from Michael Mepham's "Book of Sudoku 3":

A sudoku puzzle has some "clues" filled in.
A sudoku puzzle has some "clues" filled in.

Sudoku has several levels of difficulty, from easy to very hard, based on how many numbers you get to start with and where those numbers are positioned. (Michael Mepham, puzzle creator for London's Daily Telegraph, rates his puzzles as either Gentle, Moderate, Tough or Diabolical.) An easy puzzle gives you enough numbers placed in enough strategic positions to allow you to find the answer using fairly simple logic. Each puzzle has only one answer.

The best way to learn the art of sudoku is by working through a puzzle. Let's walk our way through the easy puzzle above to get a feel for the process. If you can solve an easy puzzle, you can solve a hard one -- it'll just take you more time.

Solving a Sudoku: Simple Logic

Michael Mepham's "Book of Sudoku 3" rates this puzzle as "gentle."
Michael Mepham's "Book of Sudoku 3" rates this puzzle as "gentle."

There is no right place to start a sudoku puzzle. You can shut your eyes and put your finger on the puzzle and start there, and that's as correct a place as any. Probably the most logical place to start, though, is at a row, column or box that has a lot of numbers in it. Let's take a look at the puzzle from the previous page:

Columns 4 and 6 each have six numbers filled in. Let's start the puzzle at column 4, which already has its 1, 3, 4, 5, 8 and 9.

In order to have one and only one of each digit from 1 to 9, we're going to have to provide column 4 with its 2, its 6 and its 7. But we can't just put them anywhere -- each number has a specific location in the puzzle's answer. So where does each number go? To find out, we need to look at the rows and boxes that interact with column 4. Take a look at the empty square at row 3, column 4 (3,4), and the row and box that interact with it:

To fill the empty square at row 3, column 4, we're going to have to look at column 4, row 3 and box 2.
To fill the empty square at row 3, column 4, we're going to have to look at column 4, row 3 and box 2.

The "simple logic" approach to sudoku requires only visual analysis and goes something like this: Can the 2 go in the empty square? It can't, because box 2 already has a 2, and it can only have one of each number. Can the 7 go there? Row 3 already has its 7, so we can't put a 7 there, either. That leaves us with the 6. Neither row 3 nor box 2 already has a 6, so we know the 6 is correct for that cell. We've solved our first number!

Now let's solve the rest of column 4, which still needs its 2 and its 7. The empty square at 5,4 interacts with row 5 and box 5, and the empty square at 7,4 interacts with row 7 and box 8.

Since box 5 already has its 7, we can't put a 7 in the 5,4 square. So right there we know the 2 goes at 5,4, and the 7 must go at 7,4:

We've now solved all of column 4, and we used only simple logic to do it. Since this is an easy puzzle, we could probably solve a good portion of it this way. But it's not always so clear-cut. There are strategies we can use when the solution is not so obvious, and it all starts with some little pencil marks.

Solving a Sudoku: Possible Numbers

Penciling in possible solutions for empty squares becomes crucial as sudoku puzzles get harder. But you're not guessing when you pencil in. You're simply listing the possible solutions. You shouldn't guess at sudoku -- it'll probably end up messing up the entire puzzle so that you have to start all over, because everything is interconnected.

By penciling in all of the possible numbers for each square in a given row, column or box, we can use certain strategies to solve the section. Let's look at row 7, which has four empty squares and needs a 4, a 5, a 6 and a 9.

We're going to pencil in all of the numbers that could possibly solve each empty square, respectively. So, of the numbers 4, 5, 6 and 9, which could possibly solve the square at 7,2? The 4 can't go there, because column 2 already has a 4. The 5 is a possibility, because neither row 2 nor box 7 has a 5 yet. The 6 is out because box 7 has a 6 already. The 9 could go there, because row 2 and box 7 are both missing a 9. So we're going to pencil in "5 9" for the square:

Using the same process for the square at 7,5, we can eliminate the 4 and the 9 (box 8 already has one of each) and pencil in a 5 and a 6. For the square at 7,6, we can pencil in a 5 and a 6. And for the square at 7,8, any of the numbers will work:

Looking at the numbers you've penciled in, you'll notice two things: First, two of the squares have the same pair of numbers (and only those two numbers), and second, the 4 only appears once. Let's start with the 4 that only appears in square 7,8. Using what we'll call the "single occurrence" strategy, we know that if the only place a 4 can go is in 7,8, we've solved that square, because row 7 needs a 4. So now, row 7 looks like this:

Now, let's look at the repeating pair: Both 5 and 6 -- and only 5 and 6 -- can go in squares 7,5 and 7,6. What we've got here is a set of matching pairs. The 5 must go in one of those two squares, and the 6 must go in one of those two squares. Using the matching pairs strategy, we can now eliminate the 5 from the square at 7,2, because we know it doesn't go there. We've solved another square:

By the way, the "matching pairs" elimination strategy also works as "matching triplets," where you have three squares with the same trio of numbers, and only that trio of numbers, in each square.

From what we've penciled in so far, we still don't know which square gets the 5 and which gets the 6, so we'll pencil in some more numbers. Let's see what we can do with box 8, which has four empty squares and needs its 1, 2, 5 and 6.

Two of those squares are already penciled in with a matching pair of 5 and 6, so we know we can eliminate 5 and 6 as possible solutions for the other boxes. That leaves us with 1 and 2. Either one of those numbers could solve the square at 8,5 -- neither row 8 nor column 5 has a 1 or a 2. But row 9 has a 2, so we can't pencil in a 2 for the 9,5 square. Here's what we've got:

Notice anything? There's only one number in the 9,5 square. Using what Mepham dubs the lone number strategy -- probably the simplest strategy in sudoku -- we know that 1 is the solution at 9,5. And since the 1 for box 8 is at 9,5, we can eliminate the penciled-in 1 from the square at 8,5, leaving only a 2 -- and another solved square.

But we still don't know the correct position for the 5 and the 6. Solving column 6 will tell us which number solves the square at 7,6. We have three empty squares in column 6, one of which is already penciled in with all of its possible solutions:

Column 6 needs a 1, a 5 and a 6. For the square at 3,6, 1 and 5 are possibilities (row 3 already has its 6). For the square at 5,6, the only possible solution is a 6, because box 5 already has a 1 and a 5.

We now know that the solution at 7,6 has to be the 5, the solution at 3,6 has to be the 1, and the solution at 7,5 has to be the 6.

Because the interaction between rows, columns and boxes is the whole point in sudoku, solving a single square can instantly show you five other solutions. Up to now, we've used simple logic and we've looked for possible numbers for a given square. In the next section, we'll use another approach: looking for possible squares for a given number.

Solving a Sudoku: Possible Squares

This time, instead of looking for the correct number for a square, we're going to look for the correct square for a number. To do this, we're going to draw some lines. Take a look at box 6:

Box 6 needs a 4. Let's find out where it goes by eliminating all of the boxes where it can't go. There's a 4 in row 5, so we'll draw a line through that row. There's also a 4 in row 6 and columns 7 and 8. We'll draw lines through all of those.

Now there's only one open square in box 6 -- the square at 4,9. We've solved the 4.

Let's draw some more lines to find the location of the 6. We can strike through row 5, row 6 and column 9, leaving only one open square. We can put the 6 in the square at 4,8.

You now have all the knowledge you need to finish the puzzle yourself!

Using simple logic and the basic strategies we've discussed here, along with the thousands of other strategies out there developed by sudoku enthusiasts, you'll be able to solve just about any sudoku puzzle. As the difficulty increases, it'll just take you longer to solve each square because some squares won't be solvable until you've solved certain other squares -- sometimes until you've solved entire regions of the grid. As you work on more puzzles, you'll come up with your own approaches and strategies. It's all a matter of finding and cultivating your own sense of sudoku logic.

While sudoku is a game of logic, there are some puzzles that ultimately defy logic and require -- to the horror of many sudoku purists -- guessing.

Solving a Sudoku: Diabolical and Beyond

Until recently, some of Michael Mepham's diabolical-rated sudokus in London's Daily Telegraph could not be solved by logic alone. They actually required guessing at a certain point, which sudoku purists consider a real no-no. Due to the amount of controversy (and hate mail) Mepham received, he has stopped publishing puzzles that require guessing. Still, the process of solving one of these puzzles is interesting, if only because you have to know enough to be absolutely sure there are no more clues before you begin the guessing process. Mepham called the strategy "Ariadne's Thread" (see below), which entails picking one of two possible solutions for a given square and following it until you reach a solution or a dead end. If you reach a dead end, you retrace your steps to the guessing point and pick a different number.

In Michael Mepham's "Book of Sudoku 3," there's a diabolical sudoku that starts like this:

Using logic, you can get here:

But there are no more logical clues -- we're stuck. The only option left to us is to guess -- and leave our numbers penciled in so we can follow Ariadne's Thread back to our starting point if our guess turns out to be wrong. If we choose one of the squares with only two options, we've got a 50/50 chance of picking the right number. Let's go to row 2, column 1 and pick the 4. Assuming that 4 is the solution to the 2,1 square, we can solve a bunch of other squares by extension -- but we end up with a problem.

If the solution at 1,7 is a 4, then the solution at 6,7 has to be the 5. But row 6 already has a 5. So now we need to erase the solutions we drew from our guess and go back to square 2,1. This time, we'll pick the 5.

The 5 is indeed the solution to the square at 2,1, and it allows us to solve the entire puzzle.

Although Mepham stopped publishing guess-necessary sudokus in his column, you can still access them at Mepham's sudoku Web site, sudoku.org.uk.

In response to the tremendous popularity of sudoku, different versions of the puzzle have emerged to provide even more of a challenge. One type of "extreme sudoku" is 3-D sudoku. Just line up nine complete sudoku grids into a three-dimensional cube that requires complete rows, columns and boxes on three interconnected axes, and you've got yourself a 3-D sudoku puzzle. All of the same rules apply, but now you're working on multiple planes. To solve the cube, you need to work out the solutions for each of the nine grids individually, although if you download one of the dozens of 3-D sudoku computer programs, you can work on the puzzle in full 3-D glory.

Puzzle Answer from Previous Page

For more information on sudoku and related topics, check out the links on the next page.

Related Articles

More Great Links

Sources

  • "The World's Most Infectious Puzzle." The Week Magazine. http://theweekmagazine.com/article.aspx?id=1271
  • How to solve Su Doku: tips http://theory.tifr.res.in/~sgupta/sudoku/algo.html
  • Sudoku.com http://www.sudoku.com/
  • Sudoku Online: Home of the Sudokulist http://www.sudoku.org.uk/index.htm
  • Peterson, Ivars. "Sudoku Math." Science News Online. http://www.sciencenews.org/articles/20050618/mathtrek.asp