iSudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: - - PowerPoint PPT Presentation

isudoku
SMART_READER_LITE
LIVE PREVIEW

iSudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: - - PowerPoint PPT Presentation

iSudoku Computing Solutions to Sudoku Puzzles w/ 3 Algorithms by: Gavin Hillebrand Jamie Sparrow Jonathon Makepeace Matthew Harris What is Sudoku? Region 1 Column 6 A logic-based puzzle game Heavily based in combinatorics


slide-1
SLIDE 1

iSudoku

Computing Solutions to Sudoku Puzzles w/ 3 Algorithms

by:

Gavin Hillebrand Jamie Sparrow Jonathon Makepeace Matthew Harris

slide-2
SLIDE 2

What is Sudoku?

  • A logic-based puzzle game
  • Heavily based in combinatorics
  • Object: place the digits 1-9 in cells
  • f a 9x9 grid (subdivided into 3x3

regions) such that no row, column, nor region of cells contains the digit more than once

  • Initially given at least 17 clue

numbers to work with

Region 1 Row 6 Column 6

slide-3
SLIDE 3

Example Sudoku Puzzle

Given: Solution:

slide-4
SLIDE 4

Formal Definition

A formal definition of the problem of solving a Sudoku puzzle: Given an n × n Sudoku grid, the Sudoku is successfully solved if:

  • ∀ x ∈ N and i ∈ N, with x ≤ n and i ≤ n: ∃ j ∈ N (with j ≤ n) such that

numberAt(i, j) = x. (“For any given number x [between 1 and n] and row number i [between 1 and n], there is

a column number j [between 1 and n] such that x can be found in row i, column j.”)

  • ∀ x ∈ N and j ∈ N, with x ≤ n and j ≤ n: ∃ i ∈ N (with i ≤ n) such that

numberAt(i, j) = x. (“For any given number x and column number j, there is a row number i...)

  • ∀ x ∈ N and r ∈ N, with x ≤ n and r ≤ n: ∃ i ∈ N (with i ≤ n) and j ∈ N (with j

≤ n) such that regionOf(i,j) = r AND numberAt(i,j) = x.

slide-5
SLIDE 5

3 Algorithms for Solving a Sudoku

  • Backtracking
  • Dancing links
  • Crook’s Algorithm
  • Generic Algorithm
slide-6
SLIDE 6

Steps for the Backtracking Algorithm

Iterate over the cells in the puzzle, and for each cell: 1. Place a number (in the case of a 9 × 9 grid) between 1 and 9 in that empty cell. 2. Check that the placed number does not violate any of the three constraints (duplicate number in its row, column, or region). 3. If any constraint is violated, backtrack and place the next greater number in the cell. 4. Repeat until all cells have been filled.

slide-7
SLIDE 7

Results of Backtracking Algorithm

  • Tested on 100 randomly-generated (online data source) Sudoku puzzles of

varying difficulty

  • Tested on 10 puzzles for each difficulty: easy, normal, and hard difficulty (for

a total of 30 puzzles)

  • Recorded runtime and # of iterations required for each solution, as well as the

avg/min/max runtime across all solutions.

slide-8
SLIDE 8

Backtracking Results for 100 Puzzles (runtimes)

Total time taken 248.48 ms Average time per puzzle 2.48 ms Fastest solve (minimum time) 0.63 ms Slowest solve (maximum time) 14.31 ms

slide-9
SLIDE 9

Backtracking Results for Easy, Normal, Hard Puzzles

slide-10
SLIDE 10

Steps for Dancing Links Algorithm

1. Setup initial matrix with constraints, column headers, and node pointers directed to neighbors and their column headers 2. For a row satisfying a constraint, remove the column and the rows intersecting that column (ie covering a node/column) 3. If no solution is found, backtrack in the exact reverse order nodes were covered (ie uncover a node/column) 4. Continue covering until the solution to the constraints is found

slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14
slide-15
SLIDE 15

Total time taken 19.62 ms Average time per puzzle 0.1962 ms Fastest solve (minimum time) 0.1834 Slowest solve (maximum time) 0.7952

Dancing Links Results for 100 Puzzles (runtimes)

slide-16
SLIDE 16

Dancing Links Results for Easy, Normal, Hard Puzzles

slide-17
SLIDE 17

Algorithm #3 - Crook’s Algorithm

  • Crook’s Algorithm is a method to solve any sudoku puzzle using pen and

paper.

  • Determines what is possible in each cell by looking through all the

possibilities, then crosses out as it test each value.

  • Uses a preemptive sets of possible integers of the possibilities, and groups

possible sets together for a solution.

slide-18
SLIDE 18

Crook’s continued

slide-19
SLIDE 19

Steps for Crook’s Algorithm

1. Mark up the cells ie. list of numbers that the cell may contain. 2. Look at each column, row and 3x3 box and break down into preemptive sets. Break down the sets and use Occupancy Theorm whenever possible. 3. Determine if puzzle is: Finished, not possible or next step. 4. Choose an empty cell and mark a number and color. Repeat step 2 until no more preemptive sets remain. 5. Go through the markup until you solve or determine as not possible.

slide-20
SLIDE 20

Crook’s Results for Easy, Medium, Hard Puzzles

slide-21
SLIDE 21

Crook’s Results for 100 Puzzles (Run time)

Total time taken 231.64 ms Average time per puzzle 2.31 ms Fastest solve (minimum time) 0.74 ms Slowest solve (maximum time) 12.42 ms

slide-22
SLIDE 22

Conclusions

  • Based on our results, we conclude that Dancing Links will be the most

efficient based on time constraints. This result matches with our initial estimate at the beginning of the project.

  • The order of efficiency based on time(Most efficient first):
  • Backtracking
  • Crook’s Algorithm
  • Dancing Links
slide-23
SLIDE 23

Questions

1. Based on Crook’s Algorithm, what is the difference between a preemptive set and a markup? A: Markup is the list of possible values for each cell. Preemptive set are numbers that are potential occupants

  • f the cell and can be occupied by no other value.
  • 2. What differentiates brute-force with backtracking from a complete brute-force algorithm for finding Sudoku solutions?

A: Backtracking will check if the number can legally be placed in the cell.

  • 3. How can one tell the difference between an easy and hard Sudoku Puzzle?

A: The amount of conceptual moves needed to complete the puzzle

  • 4. Does backtracking for solving Sudoku puzzles perform a breadth-first or depth-first search down the decision tree?

A: Depth-first

slide-24
SLIDE 24

Questions contn

  • 5. What is one reason that causes the crook’s algorithm to slow down during harder puzzles?

A: The increase in blank spaces is one reason, because it has more cells to create the markup and preemptive sets on each one.

slide-25
SLIDE 25

Genetic Algorithm

A genetic algorithm is a metaheuristic algorithm inspired by the process of natural selection that belongs to the larger class of evolutionary algorithms.

  • 1. Create a population (vector) of random solutions
  • 2. Pick a few solutions and sort them
  • 3. Replace the worst solution with a new solution
  • 4. Check if you have a new global best fitness, if so, store the solution.
  • 5. If too many iterations go by without improvement, the entire population might be stuck in a local minimum . If so, kill the

population and start over at 1.

  • 6. Go to 2.