hackelite01 / hacktoberfest-2024

11 stars 79 forks source link

created a python script for sudoku solver using backtracking concept #39

Closed calebfelix closed 1 month ago

calebfelix commented 1 month ago

How it works:

  1. Board Representation: The Sudoku board is represented as a 9x9 grid (2D list), where 0 represents an empty cell.

  2. Find Empty Cell: The find_empty function scans the board to find an empty cell (returns the row and column).

  3. Check Validity: The is_validfunction checks if placing a number in a given position is valid according to Sudoku rules (no repeated numbers in rows, columns, or 3x3 grids).

  4. Backtracking Algorithm: The solve function uses backtracking to try placing numbers in empty positions and backtracks if it encounters an invalid configuration. This process continues until the board is completely filled and valid.

You can replace the sudoku_board with any 9x9 Sudoku puzzle, and the solver will attempt to solve it.