Sudoku Solver
February 2021
- Algorithms
- Constraint Propagation
- Pygame

About
My first-semester project for Fundamentals of Computer and Programming at Shiraz University (February 2021). Rather than brute-force backtracking, the solver computes the candidates of every empty cell and applies the same elimination techniques a person would, one deduction at a time, until none applies. The original single-script submission was later restructured, tested and extended with the triple and quad techniques.
Techniques
Applied in order, restarting from the top after every deduction:
- Naked single — a cell with exactly one candidate takes that value.
- Hidden single — a value that fits in only one cell of a row, column or box goes there.
- Naked pair / triple / quad — k cells of a unit whose candidates together are exactly k values, so those values are removed from the rest of the unit.
- Hidden pair / triple / quad — k values confined to the same k cells, so those cells keep nothing else.
Pairs, triples and quads share one implementation each (naked_subset(k) and hidden_subset(k)).
Tooling
- Command-line entry point that reads a puzzle from a file or stdin, with a
--logflag that prints every deduction. - Optional
--backtrackguess-and-check fallback for puzzles that need X-Wing-class steps. - Pygame step-through viewer: placed digits drawn large, remaining candidates small, one deduction per key press.
- pytest cases, one per technique, on small hand-made grids.