
We can group the values of each 3×3 sub-grid as follows: def get_subgrids(grid): Part of the analysis has to do with checking the values of each sub-grid. Which will return the grid as expected: > grid = create_grid(puzzle) We can populate the 9×9 Sudoku grid with the following function: def create_grid(puzzle_str): As an example, we will work with: puzzle = """043080250 That means we will have 9 lines of 9 digits each. Empty cases will be denoted by 0 and each line of the string will represent a row of the grid. Using Numpy for the gridįor the 9×9 grid, we will use Numpy arrays (the experience I got using Numpy to implement a tic-tac-toe board came in handy here). The goal is to fill the grid’s empty cases, having each digit between 1-9 appear only once in each row, column and 3×3 sub-grid.

The grid is also divided into nine 3×3 sub-grids. If you’re not familiar with it, Sudoku is a mathematical puzzle where you have a 9×9 grid partially filled with digits from 1 to 9. Setting up the Sudoku grid Sudoku: What is it? For a more efficient solution based on this one, see here. It will take too long to solve difficult Sudoku puzzles. Note: This solver is a simplified implementation.
#WEB SUDOKU COMPUTE NOTES HOW TO#
In this post we will see how to implement a simple version of the solver.

After much work, I was finally able to program a solver that recursively tried filling the empty cases and tracked back when necessary. The meat of the problem was implementing a Sudoku solver. During this week I was working on one of Project Euler’s problems.
