MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / solve_all

Function solve_all

data_structures/arrays/sudoku_solver.py:169–193  ·  view source on GitHub ↗

Attempt to solve a sequence of grids. Report results. When showif is a number of seconds, display puzzles that take longer. When showif is None, don't display any puzzles.

(grids, name="", showif=0.0)

Source from the content-addressed store, hash-verified

167
168
169def solve_all(grids, name="", showif=0.0):
170 """
171 Attempt to solve a sequence of grids. Report results.
172 When showif is a number of seconds, display puzzles that take longer.
173 When showif is None, don't display any puzzles.
174 """
175
176 def time_solve(grid):
177 start = time.monotonic()
178 values = solve(grid)
179 t = time.monotonic() - start
180 ## Display puzzles that take long enough
181 if showif is not None and t > showif:
182 display(grid_values(grid))
183 if values:
184 display(values)
185 print(f"({t:.5f} seconds)\n")
186 return (t, solved(values))
187
188 times, results = zip(*[time_solve(grid) for grid in grids])
189 if (n := len(grids)) > 1:
190 print(
191 "Solved %d of %d %s puzzles (avg %.2f secs (%d Hz), max %.2f secs)." # noqa: UP031
192 % (sum(results), n, name, sum(times) / n, n / sum(times), max(times))
193 )
194
195
196def solved(values):

Callers 1

sudoku_solver.pyFile · 0.85

Calls 1

time_solveFunction · 0.85

Tested by

no test coverage detected