Upload
hari-krishna
View
220
Download
2
Embed Size (px)
Citation preview
8/2/2019 Mathematics of Sudoku
1/45
The Mathematics of Sudoku
Helmer AslaksenDepartment of MathematicsNational University of Singapore
www.math.nus.edu.sg/aslaksen/
mailto:[email protected]://www.math.nus.edu.sg/aslaksen/http://www.math.nus.edu.sg/aslaksen/mailto:[email protected]8/2/2019 Mathematics of Sudoku
2/45
Sudoku grid
9 rows, 9 columns, 9 3x3 boxes and 81 cells
I will refer to rows, columns or boxes as units
(p,q) refers to row p and column q I number the boxes left to right, top to bottom
8/2/2019 Mathematics of Sudoku
3/45
Rules
Fill in the digits 1 through 9 so that everynumber appears exactly once in every unit(row, column and box)
Some numbers are given at the start toensure that there is a unique solution
8/2/2019 Mathematics of Sudoku
4/45
History of Sudoku
Retired architect Howard Garns ofIndianapolis invented a game calledNumber Place in May 1979
Introduced in Japan in April1984 under the
name of Sudoku (), meaning singlenumbers
Took the UK by storm in late 2004
8/2/2019 Mathematics of Sudoku
5/45
Latin squares
In 1783, Euler introduced Latin squares,i.e., n x n arrays where 1 through nappears once in every row and column
A Sudoku grid is a 9x9 Latin square wherethe 9 3x3 boxes contains 1 through 9 once
8/2/2019 Mathematics of Sudoku
6/45
How many givens do we need toguarantee a unique solution?
This is an unknown mathematical problem
There are examples of uniquely solvablegrids with 17 givens(www.csse.uwa.edu.au/~gordon/sudokumin.php)
8/2/2019 Mathematics of Sudoku
7/45
How many givens can we have
without guaranteeing a unique
solution?2 8 3 6 7 1 9 4 5
9 7 6 5 4 3 1
4 1 5 3 9 7 65 6 7 4 1 9 3 8 2
8 3 4 2 6 7 1 5 9
1 9 2 8 3 5 4 6 73 2 1 7 8 6 5 9 4
7 5 8 9 2 4 6 1 3
6
4
9
1
5
3
7
2
8
8/2/2019 Mathematics of Sudoku
8/45
How many Sudoku grids are there?
It was shown in 2005 by BertramFelgenhauer and Frazer Jarvis to be6,670,903,752,021,072,936,960
This is roughly 0.00012% the number of99 Latin squares
8/2/2019 Mathematics of Sudoku
9/45
Why Sudoku is simpler than reallife
If a number can only be in a certain cell,then it must be in that cell
8/2/2019 Mathematics of Sudoku
10/45
Elementary solution techniques
We will first describe three easytechniques
Scanning (or slicing and dicing)
Cross-hatching
Filling gaps
8/2/2019 Mathematics of Sudoku
11/45
Scanning
We can place 2 in (3,2)
You should start scanning in rows or
columns with many filled cells Scan for numbers that occur many times
4 2 8 3
8 1 4 2
7 6 8 5 4
8/2/2019 Mathematics of Sudoku
12/45
Cross-hatching
8/2/2019 Mathematics of Sudoku
13/45
Filling gaps
Look out for boxes, rows or columns withonly one or two blanks
8/2/2019 Mathematics of Sudoku
14/45
Intermediate techniques
The elementary techniques will solve easypuzzles
I will discuss one intermediate technique,box claims a row (column) for a number
8/2/2019 Mathematics of Sudoku
15/45
Box claims a row (column) for anumber
Box 1 claims row 1 for number 1
We can place 1 in (3,8)
4 2 8 3
8 1 4 2
7 2 6 8 5 4
8/2/2019 Mathematics of Sudoku
16/45
Box claims a row (column) for anumber
Box 2 claims row 3 for number 8
We can place 8 in (2,9)
This is sometimes called pointingpairs/triples
8 6
5 6 1
4
8
8
8/2/2019 Mathematics of Sudoku
17/45
Advanced techniques
For harder puzzles, we must pencil in candidatelists
This is called markup
8/2/2019 Mathematics of Sudoku
18/45
Candidate Lists
8/2/2019 Mathematics of Sudoku
19/45
Strategy
If you believe the puzzle is easy, youshould be able to solve it using easytechniques and it is a waste of time to
write down candidate lists
If you believe the puzzle is hard, youshould not waste your time with too much
scanning, and go for candidate lists aftersome quick scanning
8/2/2019 Mathematics of Sudoku
20/45
Single-candidate cell
5 is the only candidate in (3,3) Called a naked single
169 4589
2 74589
459
35
8/2/2019 Mathematics of Sudoku
21/45
Single-cell candidate
(1,2) is the only square in which 6 is acandidate
Called a hidden single
169 4589
2 74589
459
35
8/2/2019 Mathematics of Sudoku
22/45
Strategy
Once you fill one cell, you must update allthe affected candidate lists
Search systematically for naked or hiddensingles in all units
8/2/2019 Mathematics of Sudoku
23/45
Naked pairs
Cells 2 and 5 only contain 1 and 7
Hence 1 and 7 cannot be anywhere else! We can remove 1 and 7 from the lists in all
the other cells
8/2/2019 Mathematics of Sudoku
24/45
Hidden pair
6 and 9 only appear in cells 1 and 5
Hence we can remove all other numbersfrom those two cells, {6, 9} becomes anaked pair and we get a hidden {1}
69 35 357 348 692
578 4781
69 35 357 348 692
578 478 1357
14569
35 357 348 1569 2
578 478 1357
8/2/2019 Mathematics of Sudoku
25/45
Naked triples
Cells 2, 3 and 7 only contain a subset of{3, 5, 6}
Hence 3, 5 and 6 cannot be anywhereelse
We can remove 3, 5 and 6 from the lists inall the other cells
8/2/2019 Mathematics of Sudoku
26/45
Naked triples
Notice that none of the three cells need tocontain all three numbers
{3, 5, 6} still forms a triple in cells 2, 3 and7 even though all the three lists onlycontain pairs
13458
35 36 3458
1672
56 46789
14679
8/2/2019 Mathematics of Sudoku
27/45
Naked and hidden n-tuples
We can generalize the pairs and triples tonaked and hidden n-tuples
If n cells can only contain the numbers
{a1,, an}, then those numbers can beremoved from all other cells in the unit
If the n numbers {a1,, an} are only
contained in n cells in an unit, then allother numbers can be removed fromthose cells
8/2/2019 Mathematics of Sudoku
28/45
Naked or hidden?
Naked means that n cells only contain nnumbers
Hidden means that n numbers are onlycontained in n cells
Naked removes the n numbers from othercells
Hidden removes other numbers from the ncells
Hidden becomes naked
8/2/2019 Mathematics of Sudoku
29/45
Row (column) claims box for anumber
In the middle row, 2 can only occur in thelast box
Hence we can remove it from all the othercells in the box
Also called box line reduction strategy
8/2/2019 Mathematics of Sudoku
30/45
Row (column) claims box for anumber vs. box claims row
(column) for a number Row claims box for a number means that if
all possible occurrences of x in row y are
in box z, then all possible occurrences of xin box z are in row y
Box claims row for a number means that if
all possible occurrences of x in box z arein row y, then all possible occurrences of xin row y are in box z
8/2/2019 Mathematics of Sudoku
31/45
More advanced techniques
X-Wing
Swordfish
XY-wing
8/2/2019 Mathematics of Sudoku
32/45
X-Wing
We can remove the 6's marked in thesmall squares and we can place 9 in (7,9).
8/2/2019 Mathematics of Sudoku
33/45
X-Wing Theory
Suppose we know that x only occurs as acandidate twice in two rows (columns),and that those two occurrences are in the
same columns (rows) Then x cannot occur anywhere else in
those two columns (rows)
8/2/2019 Mathematics of Sudoku
34/45
Swordfish
This is just a triple X-wing
Suppose we know that x occurs as acandidate at most three times in threerows (columns), and that thoseoccurrences are in the same columns(rows)
Then x cannot occur anywhere else inthose three columns (rows)
8/2/2019 Mathematics of Sudoku
35/45
Swordfish 2
We can place a 2 in (5,2)
8/2/2019 Mathematics of Sudoku
36/45
Swordfish 3
We dont need nine candidate lists
8/2/2019 Mathematics of Sudoku
37/45
XY-wing
We can eliminate z from the cell with a ?
If there is an x in the top left cell, there has
to be a z in the top right cell If there is a y in the top left cell, there has
to be a z in the bottom left cell
8/2/2019 Mathematics of Sudoku
38/45
XY-wing
We dont need a square; it is enough that
there are three cells of the form xy, xz andyz, where the xy is in the same unit as xz
and the same unit yz
We can eliminate z from the gray cellsbelow
8/2/2019 Mathematics of Sudoku
39/45
What if youre still stuck?
Sometimes even these techniques dont
work
You may have to apply proof by
contradiction
Choose one candidate in a list, and seewhere that takes you
If that allows you to solve the grid, youhave found a solution
8/2/2019 Mathematics of Sudoku
40/45
Proof by contradiction
If your assumption leads to acontradiction, you can strike that numberoff the candidate list in the cell
Unfortunately, you may have to branch at
several cells
8/2/2019 Mathematics of Sudoku
41/45
Solution by logic?
Some people do not approve of proof bycontradiction, claiming that it is not logic
It is obviously valid logic, but it is hard todo with pen and paper
8/2/2019 Mathematics of Sudoku
42/45
Where can I get help?
There are many Sudoku solvers availableonline
Many of them allow you to step throughthe solution, indicating which techniquesthey are using
http://www.scanraid.com/sudoku.htm
http://www.scanraid.com/sudoku.htmhttp://www.scanraid.com/sudoku.htm8/2/2019 Mathematics of Sudoku
43/45
Warning!
Sudoku is fun, but it is highly addictive
Happy Sudoku!
8/2/2019 Mathematics of Sudoku
44/45
Sample Puzzle
8/2/2019 Mathematics of Sudoku
45/45
Sample Puzzle 2