1 / 4

Sudoku Pseudo code

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.

Download Presentation

Sudoku Pseudo code

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. 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

  2. Sudoku Pseudo code • decide the prototype boolhasSolution() returns a true if the partial grid given you can be completed AND changes the grid to reflect a solution • verbalize the solution in terms of a recursive call to the prototype

  3. 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

  4. 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

More Related