1 / 77

THE SCIENCE OF THE SUDOKU SOLVER

THE SCIENCE OF THE SUDOKU SOLVER. By Omari N. Martin. Starring. Masahiko SudokuGrid. Michael “DancingLinks” Arena. Karou “DancingLinks” Sudoku. Antonio “Latin Square” Mathematico. Dexter “Exact Cover” Problem. Sarah Sparse Matrix. Alotof Sets. Renee “Cartesian Product” Lamont.

Download Presentation

THE SCIENCE OF THE SUDOKU SOLVER

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. THE SCIENCE OF THE SUDOKU SOLVER By OmariN.Martin

  2. Starring • Masahiko SudokuGrid

  3. Michael “DancingLinks” Arena

  4. Karou “DancingLinks” Sudoku

  5. Antonio “Latin Square” Mathematico

  6. Dexter “Exact Cover” Problem

  7. Sarah Sparse Matrix

  8. Alotof Sets

  9. Renee “Cartesian Product” Lamont

  10. John ColumnNode

  11. And guest starring • Donald Knuth’s Algorithm X

  12. AND NOW OUR STORY BEGINS… With a phrase

  13. Trivia: Meaning of Sudoku • "Sūji wa dokushin ni kagiru,"

  14. A typical Sudoku game.

  15. Sudoku and Mathematics • PART 1 - Sudoku and Latin Square • (Child and Parent)

  16. Sudoku and Mathematics (part 1) • So is there a difference between a Latin Square and a Sudoku grid? • YES!! • WELL ENLIGHTEN ME! • Answer: The Sudoku grid imposes the extra restriction that each box contains 9 distinct digits.

  17. Sudoku and Mathematics (part 1) Sudoku Grid (Child) Latin Square (Parent)

  18. END OF PART 1

  19. Sudoku and Mathematics PART 2 – Sudoku and the Exact Cover problem.

  20. Sudoku and Mathematics (Part 2) • The Sudoku game is an instance of the “Exact Cover” problem. • So what is the Exact Cover problem?

  21. Illustration of Exact Cover Problem • Let S = {N, O, P, E} be a collection of subsets of a universe U = {1, 2, 3, 4} such that: • N = { }, • O = {1, 3}, • E = {2, 4}, and • P = {2, 3}. • The subcollection {O, E} is an exact cover of U, since the subsets O = {1, 3} and E = {2, 4} are disjoint and their union is U = {1, 2, 3, 4}.

  22. Representing the Exact Cover using a sparse matrix • In the matrix representation, an exact cover is a selection of rows such that each column contains a 1 in exactly one selected row.

  23. Interpreting the Sudoku grid using set notation. • Let S = {s11, s12, …, s19, s21, …, s99} be the set of squares of the sudoku grid.

  24. Interpreting the Sudoku grid using set notation. • Let ri= {si1, si2, …, si9} ⊆ S be the set of squares belonging to row i. The diagram appearing on the right illustrates the squares belonging to row 8.

  25. Interpreting the Sudoku grid using set notation. • Let R = {r1, r2, …, r9} be the set of rows. • let C = {c1, c2, …, c9} be the set of columns. • The diagram illustrates these two sets.

  26. Interpreting the Sudoku grid using set notation. • Let cj = {s1j, s2j, …, s9j} ⊆ S be the set of squares belonging to column j. The diagram illustrates the squares which belong to column 5.

  27. Interpreting the Sudoku grid using set notation. • Let bk be the set of squares belonging to a block , and let B = {B1, B2, …, B9} be the set of blocks.

  28. The constraints of Sudoku • Every row, column, and square must contain each value exactly once. Each of these constraints involves pairs: pairs of rows and columns, pairs of rows and values, pairs of columns and values, and pairs of blocks and values. Our universe is going to be made up of pairs.

  29. Definition of CARTESIAN PRODUCT • Let A and B be two non-empty sets. • Then the Cartesian Product of A and B, written as A×B is defined as the set of ordered pairs (a, b) , where ‘a’ belongs to the set A and ‘b’ belongs to the set B. i.e. • A×B = { (a, b) : a ∈ A and b ∈ B }

  30. An illustration • The highlighted cell has value = 3,row = 4,column = 5 and box = 5 • Thus the pairs are: • RxC = (4,5) • RxV = (4,3) • CxV = (5,3) • BxV = (5,3)

  31. Solutions to the Sudoku grid • Consider the Cartesian productsR×C, R×V, C×V, and B×V. Each contains 81 pairs. For example R×C = {(r1,c1), ..., (r9,c9) }. The universe U is the 324 element union of these four Cartesian products. As it happens, every valid sudoku solution contains exactly these 324 pairs, no more, no less. But this set of pairs does not represent a specific solution. It represents every valid solution to the blank sudoku grid. • Note: V is the set of possible values. i.e. • V = {1,2,3,4,5,6,7,8,9}

  32. END OF SUDOKU AND MATHEMATICS

  33. SUDOKU AND COMPUTER SCIENCE • PART 1:- The Dancing Links Algorithm

  34. The “set of squares” become “link nodes” • A circular doubly-linked list( classic computer science data structure)

  35. A key observation! • With regards to the functionality of a circular doubly-linked list, the removal and insertion of a node involves only altering the links. Thus if we have a linked-list like this.. node x H 8 2 9

  36. Deleting a node from a linked-list • x.left.right ← x.right; • Results in…. node x 8 H 2 9

  37. Deleting a node from a linked-list • x.right.left ← x.left; //removes node x • Results in…. node x 8 H 2 9

  38. Deleting a node from a linked-list • And x.left.right ← x; • Results in…. node x 8 H 2 9

  39. Deleting a node from a linked-list • x.right.left ← x; //restores x’s position in the list • Thus… node x 8 H 2 9

  40. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 1.If the matrix A is empty, the problem is solved; terminate successfully. • Matrix A

  41. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 2. Otherwise choose a column c. • (The general heuristic is to choose the column with the lowest number of 1’s.) • Thus we select Column 1

  42. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 3. Choose a row r such that Ar,c = 1 • Row A and B qualify, however row A is selected first.

  43. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 4. Include row r in the partial solution. • PARTIAL SOLUTION = • 1 2 3 4 5 6 7 A 1 0 0 1 0 0 1

  44. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 5.For each column j such that Ar,J = 1, (outer loop) • Therefore the columns that the algorithm will operate on are 1, 4 and 7.

  45. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 5(i) For each row i such that Ai, j = 1, (inside loop) • These rows are: A,C,E and F.

  46. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 5.(ii) Delete row i from matrix A; • So delete these rows: • Before After

  47. Algorithm X by Donald KnuthThe Essence of the Dancing Links • 5(iii) Delete column j from matrix A. • So delete these columns: • Before After

  48. Algorithm X by Donald KnuthThe Essence of the Dancing Links • Repeat this algorithm recursively on the reduced matrix A. • After one run of the algorithm , the matrix A is

  49. Algorithm X by Donald KnuthThe Essence of the Dancing Links • However, this branch of the algorithm will terminate unsuccessfully.

  50. Algorithm X by Donald KnuthThe Essence of the Dancing Links • Row A is discarded from the partial solution. • PARTIAL SOLUTION: • 1 2 3 4 5 6 7 A 1 0 0 1 0 0 1

More Related