Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24,...

30
Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006

Transcript of Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24,...

Page 1: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Mathematical Methods In Solving Sudoku Puzzles

By: Cory Trenkamp

Wright State University

May 24, 2006

Page 2: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

What is a Sudoku Puzzle?

A Sudoku Puzzle is a logic-based puzzle Most puzzles are a 9 by 9 grid or matrix Each grid is further reduced into 9

separate 3 by 3 subgrids, which I will refer to as regions throughout this presentation.

Page 3: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

An example

Page 4: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Objective of the puzzleObjective of the puzzle

• Arrange the numbers 1 through 9 in each row, column and region so the numeral only shows up once.

• In every puzzle, a certain number of givens will be provided in order for you to solve the puzzle.– Givens are simply numerals provided from the

beginning.

Page 5: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

As you can clearly see: each row, column and region contain the numerals 1 through 9 only once. This must hold true for every other row, column and region as well.

Page 6: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

The History of SudokuThe History of Sudoku

Although the origin of the Sudoku name is Although the origin of the Sudoku name is Japanese, it was actually created in New York in Japanese, it was actually created in New York in the 1970s by a company called Dell puzzle the 1970s by a company called Dell puzzle magazine. They called the puzzle “Number magazine. They called the puzzle “Number Place”. As Dell continued to quietly churn out Place”. As Dell continued to quietly churn out Number Place through the Eighties, it was Number Place through the Eighties, it was spotted, imitated and embraced in puzzle-spotted, imitated and embraced in puzzle-obsessed Japan. Publisher Nicola renamed it obsessed Japan. Publisher Nicola renamed it Sudoku - in Japanese Su means a number and Sudoku - in Japanese Su means a number and doku translates as singular.doku translates as singular.

Page 7: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

History continued

A sudoku grid is a special case of a mathematical object called a Latin square. A Latin square consists of n sets of numbers from 1 to n arranged in a square pattern so that no row or column contains the same number twice. There are two Latin squares of order two (n = 2), 12 of order three, and 576 or order four.

Page 8: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Order Number of Latin Squares

1 1

2 2

3 12

4 576

5 161280

6 812851200

7 61479419904000

8 108776032459082956800

9 5524751496156892842531225600

10 9982437658213039871725064756920320000

Page 9: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

•Latin Squares were first discovered by the great mathematician Leonard Euler in 1783. He first named the squares “nouveau espece de cares magiques”, translating to “the new kind of magic squares”. Latin squares got their name due to the fact that Euler used Latin symbols to display the properties of these special matrices.

•So even if you did not know it, every time you solve a Sudoku puzzle you’ve created a Latin Square. Congratulations!

Page 10: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Lets solve these things

The strategy for solving a puzzle generally comprises a combination of three processes: Scanning, Marking up, and Elimination.

Page 11: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Scanning SCANNING is performed at the outset and periodically

throughout the solving process. It is made up of two basic techniques, which may be alternated: The first involves counting 1–9 in rows, columns, and 3 x 3 regions

to identify missing numbers. Counting based upon the last number discovered may speed up the search. It also can be the case that the value of an individual box can be determined by counting in reverse — that is, scanning its 3 x 3 region, row, and column for values it cannot be, to see which is left.

The second method, referred to as cross-hatching, involves the scanning of rows or columns to identify which line in a particular region may contain a certain number by a process of elimination. For fastest results, the numbers are scanned in order of their frequency. It is important to perform this process systematically, checking all of the digits 1–9.

Page 12: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Marking Up

Scanning comes to a halt when no further numbers can be discovered. From this point, it is necessary to engage in some logical analysis. Many find it useful at this stage to lightly pencil in possible numbers in the blank boxes. It helps to begin in the regions that already have the most numbers filled in, as there will be fewer possibilities for the empty boxes. Once all the possibilities have been filled into the empty boxes, it is necessary to analyze the diagram and start a process of Elimination.

Page 13: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

EliminationProgress is made by eliminating numbers from one or more

boxes so that you’re left with just one choice. After a number has been discovered, it generally helps to perform another scan to see the effect this number has on the rest of the puzzle. Boxes with the same combinations of possible numbers are said to be matched if the amount of penciled-in numbers in each box is equal to the amount of boxes containing them. For instance, boxes within a particular row, column, or region are said to be matched if two of them contain the same pair of possible numbers (for example 3 and 5) and no others, or if three boxes contain the same three possibilities (say, 3, 5, and 6), and no others. When this happens, you can automatically delete these numbers (3, 5, 6) that were penciled in elsewhere in the same row, column, or region as possible choices.

Page 14: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

More methodsMore methodsMore methodsMore methods

Page 15: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Naked Single

This technique is also called "sole candidate"

It is often the case that a cell can only possibly take a single value, when the contents of the other cells in the same row, column and block are considered. This is when, between them, the row, column and block use eight different digits, leaving only a single digit available for the cell.

1

7

2 9

4

8 3 ?

5

Page 16: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Hidden Single

This technique is also called "unique candidate."

If a cell is the only one in a row, column or block that can take a particular value, then it must have that value. This is because all rows, columns and blocks, must contain each of the digits 1 to 9.

2

?

8

9

2

Page 17: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Region and Column / Row Interactions

Sometimes, when you examine

a region, you can determine

that a certain number must be

in a specific row or column,

even though you cannot

determine exactly which cell in

that row or column. This is

enough information to remove

that number from the candidate

list for other cells in the same

row or column, but outside the

region.

1 2

5

3 4

*

*

*

*

*

*

Page 18: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Region / Region Interactions

If a number appears as candidates for only two cells in two different regions, but both cells are in the same column or row, it is possible to remove that number as a candidate for other cells in that column or row.

1

2 3 4

* * 6

8 * 9

1

* 7 2

X X

X X

X X

Page 19: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Naked Subset

This technique is also called "naked pair" if two candidates are involved, "naked triplet" if three, or "naked quad" if four. It is sometimes called "disjoint subset".

If two cells in the same row, column or block have only the same two candidates, then those candidates can be removed from the candidates of the other cells in that row, column or block. This is because one of the cells must hold one of the candidates, and the other cell must hold the other candidate - so neither can go in any of the other cells.

This technique can be applied to more than two cells at once, but in all cases, the number of cells must be the same as the number of different candidates.

Page 20: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

For example, consider a row that has the candidates:

{1, 7}, {6, 7, 9}, {1, 6, 7, 9}, {1, 7}, {1, 4, 7, 6}, {2, 3, 6, 7}, {3, 4, 6, 8, 9}, {2, 3, 4, 6, 8}, {5}

(The single {5} indicates that this cell already holds the value 5.) You can see that there are two cells that have the same two candidates 1 and 7. One of these cells must hold the 1, and the other cell must hold the 7, although we don't know which is which. So 1 and 7 can be removed from the candidates for the other cells. This reduces the candidates to:

{1, 7}, {6, 9}, {6, 9}, {1, 7}, {4, 6}, {2, 3, 6}, {3, 4, 6, 8, 9}, {2, 3, 4, 6, 8}, {5}So now there are two cells that have 6 and 9 as the only candidates. Repeating

the process for these numbers leaves:{1, 7}, {6, 9}, {6, 9}, {1, 7}, {4}, {2, 3}, {3, 4, 8}, {2, 3, 4, 8}, {5}Now we have a cell with a single candidate - i.e. we have reduced the

candidates to the extent that we have determined the only value that can possibly go into this cell.

Page 21: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Hidden Subset

This technique is known as "hidden pair" if two candidates are involved, "hidden triplet" if three, or "hidden quad" if four. It is sometimes called "unique subset".

This technique is very similar to naked subsets, but instead of affecting other cells with the same row, column or block, candidates are eliminated from the cells that hold the subset. If there are N cells, with N candidates between them that don't appear elsewhere in the same row, column or region, then any other candidates for those cells can be eliminated.

Page 22: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

For example, consider a region that has the following candidates:

{4, 5, 6, 9}, {4, 9}, {5, 6, 9}, {2, 4}, {1, 2, 3, 4, 7}, {1, 2, 3, 7}, {2, 5, 6}, {1, 2, 7}, {8}

(The single {8} indicates that this cell already holds the value 8.) You can see that there are only three cells that have any of the candidates 1, 3 or 7. Three candidates with only three possible cells between them means that one of the candidates must be in each of the cells. So, these three cells cannot hold any other value, meaning we can eliminate any other candidates for these cells.

In this example, we're left with:{4, 5, 6, 9}, {4, 9}, {5, 6, 9}, {2, 4}, {1, 3, 7}, {1, 3, 7}, {2, 5,

6}, {1, 7}, {8}

Page 23: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Other methods

Ariadne's Thread is used for the extremely difficult puzzles. It 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.

Computer scientists have written algorithms that solve these puzzles quickly and accurately but are too long to discuss for this presentation.

Page 24: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Cory T’s Sudoku “cheat”

Since it is known that every row, column and region contains the numbers 1 through 9, you can easily set up a formula in Excel to help guide you. Simply set each row, column and region to the summation of all numbers (which is 45). Then as you fill in your grid, subtract each entry from the total. This will give you a visual check and with time allows you to pick up on patterns.

Page 25: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

Interesting Discoveries

Many scientists have testified that Sudoku is more challenging than crossword puzzles and it benefits people with a mental workout. Even a Teachers magazine which is backed by the government recommended Sudoku as brain exercise in classrooms. Some studies suggest that Sudoku solving is capable of slowing the progression of Alzheimer's.

Page 26: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

continued

Not every Sudoku puzzle has one unique

answer, it all depends on the amount of “givens” and the location of the “givens”.

Puzzles that have only one unique solution are called proper puzzles. An irreducible puzzle is a proper puzzle from which no givens can be removed, leaving it a proper puzzle.

Page 27: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

continued

The degree of difficulty depends directly on the amount of “givens” and the location of the “givens”. Most newspapers start the week off with a

simple puzzle and with each passing day, they increase the difficulty. So by the end of the week, you are left with the most difficult puzzle.

Page 28: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

continued Minimal Sudoku

The lowest known is 17 givens in a general Sudoku. It is conjectured that these puzzles are the best possible in terms of difficulty.

Gordon Royle has collected a total of 36,628 distinct Sudoku with 17 givens. He has checked each one using the following:

Permutations of the 9 symbols Transposing the matrix Permuting rows within a single region Permuting columns within a single region Permuting the regions row-wise Permuting the regions column-wise

*There are currently no known solvable Sudoku puzzles with less than 17 givens.

Page 29: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

The Global Craze

Today there are Sudoku clubs, chat rooms, strategy books, videos, mobile phone games, card games, competitions and even a Sudoku game show. Sudoku has also sprung up in newspapers all over the world and is commonly described in the world media as "the Rubik's cube of the 21st century" and as the "fastest growing puzzle in the world".

Page 30: Mathematical Methods In Solving Sudoku Puzzles By: Cory Trenkamp Wright State University May 24, 2006.

The End

• I hope my addiction has been passed onto you.

• Questions?• Comments?• Concerns?