MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / solve

Function solve

projects/Sudoku-Solver/sudokutools.py:61–75  ·  view source on GitHub ↗

Solves the Sudoku board via the backtracking algorithm

(board)

Source from the content-addressed store, hash-verified

59
60
61def solve(board):
62 """Solves the Sudoku board via the backtracking algorithm"""
63
64 empty = find_empty(board)
65 if not empty: # no empty spots are left so the board is solved
66 return True
67
68 for nums in range(9):
69 if valid(board, empty, nums + 1):
70 board[empty[0]][empty[1]] = nums + 1
71
72 if solve(board): # recursive step
73 return True
74 board[empty[0]][empty[1]] = 0 # this number is wrong so we set it back to 0
75 return False
76
77
78if __name__ == "__main__":

Callers 3

generateFunction · 0.90
__init__Method · 0.90
sudokutools.pyFile · 0.70

Calls 2

find_emptyFunction · 0.85
validFunction · 0.85

Tested by

no test coverage detected