Sudoku Logic

Initializing live version
Download to Desktop

Requires a Wolfram Notebook System

Interact on desktop, mobile and cloud with the free Wolfram Player or other Wolfram Language products.

Sudoku is played on a grid of square cells with nine subgrids called blocks. The object of the game is to fill in all the cells with the numbers 1 to 9 such that no row, column, or block contains the same number twice. A particular puzzle starts with some cells filled with numbers that are called the clues.

[more]

This Demonstration lets you solve several given puzzles or create a new puzzle. The Demonstration does not make any deductions on its own; it is designed to assist in the reasoning process by illustrating various logical steps and solution techniques.

To solve a puzzle, you first analyze the clues (shown in blue) to determine the possibles (shown as small green numbers or squares), which are the potential candidates for a given cell (snapshot 5).

You then apply various techniques to make a choice (shown in red), which may be tentative. You can change a choice if it turns out to be wrong.

You can use various controls to create links (colored arcs) that connect possibles to indicate alternative choices and their logical consequences. See [1, Section 12] for details.

To make a reasoned choice, you must use various techniques (described in the References) to determine which possibles should become choices.

For instance, in snapshot 1, column three has the seven clues 2, 4, 5, 6, 7, 8, and 9 leaving 1 and 3 as possibles in i3 and b3. If the choice for i3 is 3, then h2 must be 9.

[less]

Contributed by: Jim Wiggins (June 2016)
Based on a program by Ed Pegg Jr and Eric W. Weisstein
Open content licensed under CC BY-NC-SA


Snapshots


Details

Controls

The display is organized into a central plot area for the Sudoku grid and three menu panels.

Cell Contents and Links

A cell can contain a single clue, a single choice, or multiple possibles.

You can connect possibles in two different cells with a link.

Cell Contents

To enter data into a particular cell:

1. Make sure that "Link Editor" is unchecked.

2 Under "Edit", select one of "Clue", "Choice", or "Possibles".

3. Click the cell.

This places a question mark cursor in the cell and enables the left menu panel.

4. Pick one number for "Clues" or "Choices" or multiple numbers for "Possibles".

5. Use "Select" to update the cell contents or "Cancel" to revert. The controls in the top and right menu panels are disabled until you select or cancel.

The three "Edit" controls determine the type of data entered in each cell.

Links

You can create and edit links between two possibles in different cells. To enter or modify a link, check the "Link Editor" control. This enables the five controls under it and displays a link cursor (long black arrow).

For example, do the following:

1. Select the "Forcing Chains" bookmark.

2. Select "Poss.+Links" under "Content" to see a full set of links.

3. Check the "Link Editor" to see the link cursor as well (snapshot 1).

4. Click "Delete All" to delete all the links.

5. Drag the tail of the link cursor (red circle, see snapshot 1) to the center of cell b3.

6. Shift-click the top-left possible labeled “1” in cell b3; the tail end of the link cursor snaps to label 1.

7. Drag the head of the link cursor to the center of cell i3.

8. Shift-click the top-right possible labeled “3” in cell i3; the arrow tip of the link cursor snaps to label 3.

9. Click "Add".

An arc is drawn in the specified color and with the specified curvature between the two possibles (snapshot 2).

If the link cursor targets are not close enough to the vertex centers, a beep sounds and no link is created.

The link from 1 in b3 to 3 in i3 indicates that if b3 is 1, then i3 must be 3.

10. In the drop-down curvature control (above "Form:"), select different numbers to see the changes in curvature, both positive and negative (snapshot 3).

If you change the curvature control without there being an existing link, a beep sounds.

11. Click "Delete"; the current link is deleted but the link cursor stays in place.

12. Change the color in the drop-down control and then click "Add"; a new link of the specified color and curvature appears (snapshot 4).

13. Uncheck "Link Editor", and select the “Forcing Chains” puzzle from "Puzzles" to again see the default set of links for that puzzle (snapshot 1).

The links show that regardless of whether b3 is 1 or 3 (the only two possible choices), there must be a 1 in h4.

14. To delete or modify an existing link, check "Link Editor", and position the link cursor over an existing link in the same direction. Click "Delete" to delete the link or to later change the color. Or select a different curvature in its drop-down control.

If the link cursor is not correctly aligned with the existing link, a beep sounds.

Puzzles

You can select three different puzzles with "Puzzles" in the left menu panel or clear various default values (snapshot 5; "XY-Chain" puzzle selected).

Puzzle selection is disabled if "Link Editor" is checked, or if data is being entered (a question mark is in a cell).

Form

On the right under "Form", select "Grid" to show the content data in the standard grid; select "Text" to show the current data (snapshot 6).

Content

On the right, under "Content", "Poss.+Links" displays both the possibles and any links you have created. Click "Possibles" to see the possibles without the links. Deselect "Possibles" to hide both the possibles and links.

Graph

At the bottom-right under "Graph", select "Vertices" to display green squares in a small grid for the possibles within each cell. Select "Labels" to show the numbers 1 to 9 in those locations.

Advanced: Opening and Saving Files

You cannot open or save files in a CDF; you can using Mathematica.

To enable the open and save functions in Mathematica, set the variable fileEnable to True in the code for this Demonstration, and then re-evaluate the Manipulate cells.

Select "Advanced" at the bottom-left. "Open" and "Save" buttons appear at the top that let you open files created with Sadman Software Sudoku [2] or save changes to them in the same format.

You can view the saved .sdk file (which is largely text) in a text editor; the format is virtually identical to that used by Sadman Software Sudoku [2]. You can use that program to select from a very large variety of puzzles, covering a wide range of difficulty, and which can illustrate different methods of solution. They can be partially solved there, saved to an .sdk file, and then loaded to this Demonstration, which can then be used to graphically illustrate the logical sequences used in various solution techniques. Modifications made here can then be saved to the same or a different file.

If the Sadman Software Sudoku program is not available then the other controls in this Demonstration can be used to create new puzzles and sequence links from scratch that can then be saved and reloaded.

References

[1] T. Davis. "The Mathematics of Sudoku." (May 24, 2016) precollegiate.stanford.edu/circle/math/notes08f/sudoku.pdf.

[2] S. Armstrong. "SadMan Software Sudoku." (May 24, 2016) www.sadmansoftware.com/sudoku.

[3] J. Rosenhouse and L. Taalman, Taking Sudoku Seriously, New York: Oxford University Press, 2011.



Feedback (field required)
Email (field required) Name
Occupation Organization
Note: Your message & contact information may be shared with the author of any specific Demonstration for which you give feedback.
Send