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

Function solve

projects/Sudoku_solver/main.py:121–144  ·  view source on GitHub ↗
(bo)

Source from the content-addressed store, hash-verified

119
120
121def solve(bo):
122 # searching for next empty solt
123 slot = next_empty(bo)
124 if not slot:
125 # return True if there is no empty slot
126 return True
127 else:
128 row, col = slot
129 # looping number 1 to 9
130 for i in range(1, 10):
131 # check if the number is possible in this location
132 if possible(bo, (row, col), i):
133 # placing the number on the board
134 bo[row][col] = i
135
136 # starting recursion
137 if solve(bo):
138 # returns True when the previous returned True
139 # This will only activate if the board is full
140 return True
141
142 # resetting the changed value to 0
143 bo[row][col] = 0
144 return False
145
146
147# Fill your numbers in the board below or create a new array to solve the board you give.

Callers 1

main.pyFile · 0.70

Calls 2

next_emptyFunction · 0.70
possibleFunction · 0.70

Tested by

no test coverage detected