Sudoku puzzles on Linux

A Game of Logic


Some regard Sudoku as the 21st century Rubik's Cube. We'll show you how to get started with Sudoku in Linux.

By Oliver Frommel

www.sxc.hu

Sudoko is the game this year. No matter where you are, on the subway or in the park, you'll find people poring over little boxes with numbers. Germany's Game Manufacturer's Association went so far as to say that Sudoku would be next year's mega-trend. All of this hype has prompted toy manufacturers to exhibit no less than ten different Suduko clones disguised as new games.

If you prefer a low-budget version, you can just let your Linux computer design the puzzles for you and then print them out, filling in the squares at your own leisure. Unlimited gaming is guaranteed, as a 9 by 9 puzzle gives you over 6 x 1021 different combinations [1]. In fact, you would need several lives to exhaust all of these possibilities. For more on Sudoku, check out the Wikipedia article [2]. Many newspaper websites give you Sudoku puzzles online, and there are two Sudoku puzzles (beginner and expert level) for you to try out at the end of this article.

Logical

Sudoku is based on a very simple idea. You have to fill all the empty squares in the 9 x 9 box so that the numbers 1 through 9 appear just once in each row, column, and 3x3 box (see Figure 1). The name Sudoku is Japanese and means something like "numbers singly." Based on these rules and the existing numbers, the player has to restrict the choice of entries for an empty square until just one candidate is left.

Figure 1: Gnome-Sudoku devises puzzles and gives you tips for solving them.

There is no need to add the numbers or perform any kind of calculations. Playing Sudoku means relying on your power of deduction, and it helps if you have a good memory. Some players simply note their possible solutions in a corner of each box to remind themselves of what they were thinking of later on.

There are several strategies to solving a puzzle. For example, it makes sense to think about which numbers are missing in a 3 by 3 box, then to check intersecting rows and columns for these numbers. If the number exists in an intersecting row or column, you can rule it out in the 3 by 3 box. In many cases, this just leaves one possible solution, and that means you can add the number to the square.

Computer Help

Of course, this kind of logic game is perfect for computing. The simplest Sudoku games just give you a puzzle and let you solve the puzzle on your computer. Gnome fans will prefer Gnome-Sudoku [3], a Python program. It can devise Sudoko puzzles of varying levels of difficulty. The player can solve the puzzle by entering numbers directly in a Gnome window (Figure 1).

You need Python 2.4 to install Gnome-Sudoku. (Only the latest Linux distributions have Python 2.4.) Gnome-Sudoku works quite well in principle, but it is still fairly buggy. Although the bugs do not typically cause crashes, they can slow the game. The trouble starts when you use the slider to select a skill level, from Easy to Hard. As this has no visible effect, you might prefer to check for the list in the same dialog box to find a game with your preferred skill level.

Gnome-Sudoko does have some saving graces, such as a practical feature known as the Tracker. The Tracker lets you record a number of moves and then revert to your previous position with a single click. Of course, there is also an undo function that lets you undo individual moves.

Gnome-Sudoku can also give hints. In fact, you can hover the mouse over a square to view the possible candidates for that square. If the cursor is outside of a square when you ask for a hint, the program gives you an error message instead. There is a Resume Game option that lets you carry on an interrupted game from where you left off. Gnome-Sudoku also has a help feature that gives newcomers an introduction to the principles of the game and explains now to use the program.

Convenience with a K

The KDE counterpart to Gnome-Sudoku is Ksudoku. The Ksudoku program only requires the KDE libraries if you want to build from the source, and there are binary packages for Fedora and Debian on the homepage [4]. After typing ksudoku to launch the program, you should see a window like the one in Figure 2.

Figure 2: Ksudoku shows you an empty grid at the start of the game. The program highlights the row, column, and current 3 by 3 box.

The fact that Ksuduko highlights the row, the column, and the three by three box belonging to the square with the mouse cursor is typical of the added convenience that the KDE program gives you in comparison with Gnome-Sudoku.

Ksudoku gives you two ways of adding a number to a square. You can select the number in the vertical toolbar on the left and then left click a square, or you can press a numeric key on your keyboard. If your entry is wrong, the program will color the number red. You can then right click the number to remove your entry.

One of Ksudoku's more practical features is its ability to store notes on potential candidates for a field. To use this ability, use the menu or your keyboard to choose a number, and then right click. Ksudoku enters the candidate in the field using a small font. Although any number of entries is possible, the software can only display four entries due to the font size.

Getting Help

If you click Hint, Ksudoku simply fills the current square. The Shift key gives you a more subtle form of help. Ksudoku shows you the other squares where the same number would fit (Figure 3). Of course, this is a big help in comparison to analog, paper-based Sudoku. So if you really want to see how good you are at solving Sudoku puzzles, you should avoid becoming dependent on the help.

Figure 3: With the Shift key, Ksudoku shows you all the squares that could contain the same number as the field with the mouse cursor (here the 6 in the center). All other squares are colored pink.

The help function is extremely terse; it does not give you instructions for the program or for the game itself. Instead, Ksudoku has a 3D mode that gives you a three-dimensional model of the otherwise flat display (Figure 4). This does not change the principle of the game, but it does give experienced Sudoku players a new and interesting perspective.

Figure 4: Ksudoku has a 3D mode that follows the same rules as normal Sudoku. It just organizes the squares in a three dimensional space instead of on a two-dimensional board.

For Sudoku addicts, Ksudoku also has bigger puzzles with more than nine by nine squares. As the numbers 1 through 9 are not enough for these games, the program uses letters instead.

Besides Ksudoku and Gnome-Sudoku, there are a number of other programs centered around this popular game of logic. The Sudoku-Solver [5] puts the computer to work on solving puzzles when experts have given up. The Sudoku-Explainer [6] does not simply give you a solution; it actually analyses Sudoku puzzles and explains how to solve them. The latter program requires ASCII-formatted Sudoku input. So you have to type the puzzle in a text file, keeping to the program's own format.

Conclusions

If you insist on using a Gnome program, Gnome-Sudoku is probably the right game for you, despite its minor failings. However, Ksudoku for KDE is superior to its Gnome counterpart in most respects, starting with row and column highlighting, and it includes better hints to help you solve puzzles. My recommendation is, if you are interested in solving Sudoku puzzles on your Linux-based computer, take a look at Ksudoku.

Figure 5: Here arte two Sudoko puzzles for you tol solve. Fill the free cells so that each row, column, and region contains the figures 1 trough 9 just once. For the answer see here [7].
INFO
[1] Sudoku math: http://web.inf.tu-dresden.de/~bf3/sudoku/
[2] Wikipedia on Sudoku: http://en.wikipedia.org/wiki/Sudoku
[3] Gnome-Sudoku: http://gnome-sudoku.sourceforge.net
[4] Ksudoku: http://ksudoku.sourceforge.net
[5] Sudoku-Solver: http://sudokusolver.co.uk/
[6] Sudoku-Explainer: http://sourceforge.net/projects/sudoku-sensei
[7] http://www.linux-magazine.com/issue/63/Sudoku_Answer.pdf
THE AUTHOR

For several years Oliver was a sysop and programmer at Ars Electronica Center in Linz/Austria.

After finishing his studies in Philosophy, Linguistics and Computer Science he became an editor for the Bavarian Broadcasting Corporation. Today he is head of the Editorial Competence Center for Software and Programming at Linux New Media AG.