sudoku pseudo code

4
Sudoku Pseudo code 1.decide the prototype 2.verbalize the solution in terms of a recursive call to the prototype 3.write the code for the recursion being careful NOT to mentally trace the recursive call 4.make sure you have base cases handled 5.make sure you USE any return

Upload: naida-charles

Post on 01-Jan-2016

29 views

Category:

Documents


0 download

DESCRIPTION

Sudoku Pseudo code. decide the prototype verbalize the solution in terms of a recursive call to the prototype write the code for the recursion being careful NOT to mentally trace the recursive call make sure you have base cases handled make sure you USE any return values. Sudoku Pseudo code. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Sudoku Pseudo code

Sudoku Pseudo code

1. decide the prototype2. verbalize the solution in terms of a recursive

call to the prototype3. write the code for the recursion being careful

NOT to mentally trace the recursive call4. make sure you have base cases handled5. make sure you USE any return values

Page 2: Sudoku Pseudo code

Sudoku Pseudo code

1. decide the prototype bool hasSolution() returns a true if the

partial grid given you can be completed AND changes the grid to reflect a solution

2. verbalize the solution in terms of a recursive call to the prototype

Page 3: Sudoku Pseudo code

Verbalize the solution making sure you use hasSolution in your solution

• If the grid is complete, you have your solution• Otherwise, find ONE empty cell.• Try each possibility for the empty cell. Insert

that value into the grid If hasSolution returns true for any possible value return true

• otherwise remove your bad value from the cell and return false

Page 4: Sudoku Pseudo code

check to see if all the cells have been filled in already. If so, return true.

Find an unfilled cell. Call i,j the location of the unfilled cell.

For (choice=1 to 9){ if isOK(i,j,choice) { change grid[i][j] = choice if hasSolution() return true. grid[i][j]=0 //clean up after yourself }}return false