The Mathematica Journal
Volume 9, Issue 3


In This Issue
Tricks of the Trade
In and Out
Trott's Corner
New Products
New Publications
News Bulletins
New Resources

Download This Issue 

About the Journal
Editorial Policy
Staff and Contributors
Back Issues
Contact Information

In and Out
Edited by Paul Abbott

In-flight Puzzle

Q: This puzzle appeared in an in-flight magazine: In the following diagram, place the numbers 1 through 9 so that each row, column, and subsquare contains each number exactly once.

How can I solve this using Mathematica?

A: Bobby Treat ( answers: Here is a naïve solution that depends on there being, at each stage, at least one cell that is fully determined and that does not check for contradictions. It works for the sort of problem you would expect to encounter in an in-flight magazine.

Input the table with empty cells replaced by empty lists.

PuzzleDisplay, written by David Park (, is used to display the puzzle.

The function SubSquare finds the subtable corresponding to the element .

Excluded determines what values cannot be entered in the cell , for cells that are not yet known.

Four values are excluded for the cell .

OneChoice, applied to the cell , returns the existing value (if any), which is the only choice if eight digits have been excluded, or if the choice is not determined.

There is only one choice for the cell .

Here is the iteration step, Iterate.

And here is the animated solution. You can use the Up and Down Arrow keys to step through the animation once it has started.

About Mathematica | Download Mathematica Player
© Wolfram Media, Inc. All rights reserved.