Skip to content

Add a Sudoku solver (backtracking algorithm) #22

Description

@utk2103

Add a Sudoku solver using backtracking to scripts/.

Why

scripts/ has linear search, binary search, merge sort, and Tower of Hanoi. Backtracking is the missing algorithm family, and Sudoku is the friendliest example of it — the recursion is visible in the grid.

Suggested file

scripts/sudoku_solver.py

What it should do

  • Hold a 9×9 puzzle as a list of lists, 0 for blanks.
  • Solve it in place: find the next empty cell, try 1–9, recurse, undo on failure.
  • Print the grid before and after, in 3×3 blocks.

Acceptance criteria

  • Recursive backtracking with an explicit undo step (grid[r][c] = 0) — not a brute-force permutation generator.
  • is_valid(grid, row, col, value) checks row, column, and the 3×3 box.
  • Returns False for an unsolvable puzzle instead of hanging or crashing.
  • assert-based self-check on one known puzzle with a known solution.
  • Standard library only.
  • Short comment on why backtracking beats trying every filling.

Inspiration

sudoku-solver from Awesome-Python-Scripts.

Good first issue for anyone comfortable with recursion — comment below to get assigned.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions