All projects

Sudoku solver

A solver I wrote in Python using backtracking. Type in any puzzle below and it is solved in your browser with the same method.

How it works

The solver looks for the first empty cell, reading left to right and top to bottom, and tries the digits 1 to 9 in order.

A digit stays if it does not already appear in the same row, column or 3 by 3 box. The solver then moves to the next empty cell and repeats.

When no digit fits, it steps back to the previous cell and tries the next digit there. That stepping back is what gives backtracking its name. Press "Watch it solve" to see digits appear and vanish as the search runs.

Your numbers show in black and the solver's in blue. The grid starts with the example board from the Python script.