Just a small practice exercise that solves Sudoku by iterating over valid values for each cell and backtracking on errors. I like how compact the solution is, although probably not very performant.
from pprint import pprintfrom math import floorfrom copy import deepcopygrid = []content = Nonewith open('startgrid.txt', 'r') as file: content = file.read().replace("\n", " ").split(" ")for row in range(9): grid.append([]) for col in range(9): grid[row].append(int(content[row*9...
Published on December 29, 2024 09:08