Download - Sudoku Pseudo code
![Page 1: Sudoku Pseudo code](https://reader035.vdocument.in/reader035/viewer/2022081811/56812ff1550346895d9566b6/html5/thumbnails/1.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022081811/56812ff1550346895d9566b6/html5/thumbnails/2.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022081811/56812ff1550346895d9566b6/html5/thumbnails/3.jpg)
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](https://reader035.vdocument.in/reader035/viewer/2022081811/56812ff1550346895d9566b6/html5/thumbnails/4.jpg)
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