Presentation is loading. Please wait.

Presentation is loading. Please wait.

The mathematics behind sudoku

Similar presentations


Presentation on theme: "The mathematics behind sudoku"— Presentation transcript:

1 The mathematics behind sudoku
Laura olliverrie

2 Abstract I will explore the mathematics behind sudoku. Specifically, I will explore enumerating the number of distinct Sudoku grids, the use of computer algorithms to solve puzzles, and the application of abstract algebra and graph theory to enumerate “essentially different” sudoku grids.

3 Introduction Sudoku is a logic-based number placement-puzzle usually presented on a 9x9 grid (but there are many other variations like the 16x16 grid). Numbered puzzles appeared in French newspapers in the late 19th century. Howard Garns is credited with the invention of Sudoku. The first puzzle appeared in the magazine Dell pencil puzzles and word games in 1979 and was called Number Place. Sudoku was introduced in Japan by Nikoli in 1980s as Sūji wa dokushin ni kagiru (数字は独身に限る) and later abbreviated to sudoku which means single number (and is now a registered trademark of a Japanese puzzle publishing company). It first appeared in a US newspaper and The Times in 2004 due in large part to Wayne Gould who created a computer program to rapidly produce distinct puzzles For the purpose of this presentation, I will focus on the 9x9 grid. But the World Puzzle Championship has featured 6x6 grid with 2x3 regions, The Times offers Dodeka Sudoku with a 12x12 grid of 4x3 squares and there is also the 25x25 grob by Nikoli and the 100x100 grid dubbed Sudoku-zilla which was published in 2010. Gould spent 6 years developing the computer program Pappocom Sudoku.

4 One Rule Players insert the numbers one to nine into a 9x9 grid (81 cells) subdivided into nine 3x3 blocks in such a way that each column, row, and 3x3 block has exactly one occurrence of each number. A few numbers are given as clues to help complete the puzzle, and are aptly called givens. No basic arithmetic is required! The numbers involved can easily be replaced by shapes, colors, types of fruit and any other set A where n(A) = 9 as has already been done in the many variations of the traditional number-based Sudoku puzzles. But mathematical thinking in the form of logical deduction is very useful in solving the puzzles.

5 WOULD ANYONE LIKE to complete this puzzle?

6

7 Questions: 1) How many distinct sudoku grids are there
Questions: 1) How many distinct sudoku grids are there? 2) How many sudoku grids are “essentially different”? How would you enumerate an nxn grid?

8 Let’s begin with the 4x4 case
Goal: Count the number of valid 4x4 Sudoku grids (following the One Rule). 1) Fill the top left block in standard form. There are 4! = 24 distinct grids since there are 4! ways to relabel digits in Block 1 2) The order in which we enter 3 & 4 in the first row and 2 & 4 in the first column does not matter since swapping preserves the One Rule. There are now 4!*2*2 = 96 distinct grids Sudoku of rank n is an n2×n2 square grid, subdivided into n2 blocks, each of size n×n We may assume that 3 goes in the third cell and 4 in the fourth cell of the first row. Since 1 and 3 occur in the first column of the grid already, 2 and 4 must be placed in the third and fourth cells of that column.

9 3) We must place 4 in the (3,3) position since the only possibilities are 1 and 4, and 4 occurs in the fourth row, fourth column, and bottom right block already. 4) Now, there are 3 possible entries for the cell in the (4,4) position: 1, 2 and 3. So, there are 4!*2*2*3=288 distinct 4x4 Sudoku solutions.

10 What happens if we fill in the three possible grids from 4)?
We find that the third grid is equivalent to the second grid by reflection across the diagonal from the upper left to the bottom right and relabeling by interchanging 2 and 3. This means that there are 2 “essentially different 4x4 Sudoku grids. Rotate grid 3 out of the plane about a diagonal line running from the upper left corner to the lower right.

11 Answering question #1

12 How many Distinct sudoku grids are there?
Goal: Count the number of valid 9x9 Sudoku grids (following the One Rule). Terminology : Bands – 3 rows of blocks Stacks – 3 columns of blocks N – number of distinct Sudoku grids 1) Fill the top left block in standard form. There are 9! = ways of filling B1 N = N1*9! Bertram Felgenhauer and Frazer Jarvis method First. Label each block Second. 9! ways to fill B1 Relabeling procedure reduces the number of grids by a factor of 9! = We are reduced to counting the number N= N1 * 9! of Sudoku grids in this standard form. N1 is the number of grid completions B1 can have

13 Filling blocks *{a,b,c} indicates the numbers a, b and c in any order
We must consider all possible ways to fill in blocks B2, B3, given that B1 is in the standard form above 2) Find all the possible ways of filling the top rows of B2 and B3 {4, 5, 6}|{7, 8, 9} {7, 8, 9}|{4, 5, 6} {4, 5, 7}|{6, 8, 9} {6, 8, 9}|{4, 5, 7} {4, 5, 8}|{6, 7, 9} {6, 7, 9}|{4, 5, 8} {4, 5, 9}|{6, 7, 8} {6, 7, 8}|{4, 5, 9} {4, 6, 7}|{5, 8, 9} {5, 8, 9}|{4, 6, 7} {4, 6, 8}|{5, 7, 9} {5, 7, 9}|{4, 6, 8} {4, 6, 9}|{5, 7, 8} {5, 7, 8}|{4, 6, 9} {5, 6, 7}|{4, 8, 9} {4, 8, 9}|{5, 6, 7} {5, 6, 8}|{4, 7, 9} {4, 7, 9}|{5, 6, 8} {5, 6, 9}|{4, 7, 8} {4, 7, 8}|{5, 6, 9} We only need to count the number of ways to complete B1, B2 and B3 to a full grid, and we do not need to count the number of ways to complete B1, B2’ and B3’ First two are pure top rows The remaining 18 are mixed top rows *{a,b,c} indicates the numbers a, b and c in any order

14 possible configurations for the top three blocks
There are (3!)6 possible configurations to complete the first band starting with the pure top row (each set of three numbers can be written in 3! = 6 different ways) There are 3 × (3!)6 possible configurations to complete the mixed top rows In total, 2 × (3!) × 3 × (3!)6 = 56 × (3!)6 = possible completions to the top three rows. The number of possibilities for the top three rows of a Sudoku grid is 9! × = Possible configurations for the top three blocks, given that the first block is of the standard form {a,b,c} stands for 1,2,3 in some order (b and c are interchangeable)

15 Can we reduce the number of possibilities to improve calculation time?
Which first bands share the same number of full grid completions? Think about: Relabeling the numbers Permuting any of the blocks in the first band Permuting the columns within any block Permuting the three rows of the band All leave the number of grid completions of the first band unchanged. Able to reduce the number of first bands to be counted

16 Lexicographical reduction
By lexicographical reduction, we can permute the columns of B2 and B3 so that the top entries are in increasing order, and then exchange B2 and B3 (if necessary) to make the first entry of B2 smaller than that of B3. There are 62×2=72 other first bands with the same number of grid completions. We can now consider /72=36288 first bands. Can we reduce more? There are 6 permutations of the columns in each of the two blocks and two ways to permute the blocks.

17 Permutation and column reduction
If we consider all 6 permutations of B1, B2 and B3 and all 6 permutations of columns within each block AND consider that when we choose any permutation, we are able to relabel B1 back to standard form, there are just 416 possibilities for B2 and B3. Further, if the columns of two configurations consist of the same numbers, in any order, then the two configurations can be completed in the same number of ways There are actually only 44 first bands whose number of grid completions need to be found. They could have reduced the search a little further by doing more of the reduction steps, but the predicted running time at this point was sufficiently low

18 How many distinct sudoku grids are there?
N = number of distinct Sudoku grids Let C = 1 of the 44 possibilities Let nc = number of ways that C can be completed to a full Sudoku grid Let mc = number of possibilities for B1, B2, and B3 that are equivalent to C N=ΣCmCnC Mathematicians Bertram Felgenhauer and Frazer Jarvis found that 6,670,903,752,021,072,936,960 (6.67 x 1021) grids are possible by using logic and brute- force computation. (This was later confirmed by Ed Russel.)

19 How many sudoku grids are “essentially different”?
Answering question #2 How many sudoku grids are “essentially different”?

20 Abstract algebra refresher
A group is a set G (· ) such that: Closure: If g and h are elements of G, then so is g·h. Associativity: If g, h, and k are elements of G, then g·(h·k)=(g·h)·k.  Identity: There is an element e in G such that g· e = e · g = g for all g in G. Inverse: For any element g of G, there is another element h of G so that g·h=h·g=e, where e is the identity element.  A symmetry of an object is an operation that preserves a certain property of the object. It is interesting to note that if we perform one symmetry and then another, the resultant transformation is itself a symmetry.

21 example Consider the square.
A square has eight transformations, or eight symmetries. Rotation by 0 degrees (the identity transformation). Rotation clockwise by 90 degrees. Rotation clockwise by 180 degrees. Rotation clockwise by 270 degrees. Reflection in the horizontal axis (through the center of the square). Reflection in the vertical axis (through the center of the square). Reflection in the diagonal from the bottom left to the upper right corner. Reflection in the diagonal from the upper left to the bottom right corner.

22 Symmetries of grid The symmetry group G of a Sudoku grid consists of all the transformations of the square and more, Relabeling the nine digits. Permuting the three stacks. Permuting the three bands. Permuting the three columns within a stack. Permuting the three rows within a band. Any reflection or rotation (from the list of symmetries of a square). It is important to note that this is not a list of all the elements of G; it is a list of the kinds of symmetries that are in the group and combine to form other elements of the group

23 Russel and Jarvis method
Regard two grids as equivalent if one can be transformed into the other by relabeling. If there are no such symmetries to be used, the grids are essentially different. Want to count the number of grids which are fixed up to equivalence by a given symmetry, that is, the grids which are transformed by the symmetry into an equivalent grid. Russel and Jarvis used a program called GAP to work with groups arising by permuting sets. For all but 27 of 275 “conjugacy classes,” it can be shown that there are no grids at all transformed to equivalent grids. 275 conjugacy classes (any 2 elements in the same class will have the same number of fixed grids)

24 How many sudoku grids are “essentially different”?
When symmetries such as rotation, reflection, permutation, and relabeling are factored in, there are 5,472,730,538 essentially different grids. Russel and Jarvis also used Burnside’s lemma to find the amount of grids with differing restraints, such as not allowing reflections or permutations. Burnside's Lemma: Let G be a finite group that acts on a set X. For each g in G, let Xg denote the set of elements in X that are fixed by g. Then the number of elements of X/G is |X/G|=1/|G|Σg in G|Xg|, where |-| denotes the number of elements inside the set.

25 computing

26 Brute-force Search Problem-solving technique that consists of systematically enumerating all possible candidates for the solution and checking whether each candidate satisfies the problem's statement.

27 Backtracking A general algorithm that incrementally builds candidates to the solutions, and abandons a candidate ("backtracks") as soon as it determines that the candidate cannot possibly be completed to a valid solution. Large sets of solutions can be discarded without being explicitly enumerated. Often much faster than brute force enumeration Depth-first search because it will explore one branch to a possible solution before moving to another branch.

28 Problems with solving sudoku puzzles
As the rank of a Sudoku increases from n to n+1, the extra computational time needed to find a solution increases quite fast. The general problem of solving Sudoku puzzles on n2×n2 grids of n×n blocks is known to be NP-complete. Good Sudoku solver programs utilize a combination of strategies until a solution is reached. NP - nondeterministic polynomial time Set of decision problems that can be solved in polynomial time on a non-deterministic Turing machine

29 Further applications Are there better computing algorithms to solve a Sudoku puzzle, or n2×n2 grids. Dancing Links Sudoku is being mentioned by health professionals as a tool for mental fitness. Sudoku has been known to prevent or even mental health defects like Alzheimer’s disease and other forms of dementia.

30 Fun classic sudoku alternatives
Killer Sudoku – combines elements of sudoku and kakuro Hyper Sudoku

31 Thank you!

32 references http://www.websudoku.com/


Download ppt "The mathematics behind sudoku"

Similar presentations


Ads by Google