hans

The Omnifarium - Toronto/Sudoku.html

Sudoku Has Hit Toronto!

Thu, 02 Jun 2005, 22:05

Earlier this week, the Toronto Star began including a Sudoku puzzle in its daily newspaper. Some other local rags also include a Sudoku puzzle. Apparently, these puzzles are extremely popular in other countries, especially Japan and Britain. Ever eager to try out new puzzles, I had to give this one a go. So far, I've solved about half a dozen, and I think I've already had my fill of Sudoku.

What is Sudoku? You start with a 9x9 square grid. At first, some of the squares are already filled in with numbers. Your task (should you decide to accept it) is to fill in the empty squares with numbers from one to nine. The same number can't appear more than once in any row, column, or 3x3 box.

How do you solve it? Start by considering that each empty square can possibly hold any number from one to nine. There are then two processes you can use. First, when you know a value for one square, you can eliminate that value from each associated row, column, and box. Second, try to find squares in any row, column, or box that can only hold one particular value. For most puzzles, repeating these two processes is enough. But some puzzles require additional analysis involving studying the intersections between boxes and rows or columns.

In other words, solving a Sudoku puzzle is pretty much a systematic, analytic process. Plan on about 20 to 30 minutes to complete a puzzle, longer if you have to resort to deeper analysis. Most of that time is spent listing possibilities for each square and eliminating them one by one. If you make a mistake along the way, it usually means starting over from the beginning. Of course, a pencil with a good eraser is a necessity. The main challenge is to keep at this boring task without making any mistakes.

Since solving Sudoku puzzles is a mindless, repetitive job, I figured the best approach would be to let my computer do it. So I wrote a program. Roughly 350 lines of Python code is sufficient for the task. And writing the program was more fun than I had solving Sudoku puzzles by myself.

Hans

path: /Toronto | permanent link to this entry

the city