By Jeffrey Yang (yjeffrey) and Jerry Wang (jwang01)
Our project implements various sudoku solvers in C++, with an exploration of 3 different algorithms.
The objective of Sudoku is to fill an 9 by 9 grid with digits from 1 to 9 such that each row, column, and subgrid contains exactly one occurence of each digit. There are a variety of known techniques for solving Sudoku found here. We have implemented algorithms for backtracking, ac3, and exact cover solvers.
- Run make to compile the different sudoku solvers and also the main file.
- For each of the executables
backtrack_solver,constraint_solver, andexact_cover_solver:- Run
./executable <sudoku file> [-p]to solve the puzzles in each sudoku file.[-p]indicates whether or not you want the Sudoku game to be printed.
- Run
- We compiled the main program using
-O3optimization and you can benchmark the runtime of the different algorithms. main is ran using./main <sudoku file> <solver_type> [-p]. Below are some examples:./main puzzles/easy_list.txt backtrack./main puzzles/hard_list.txt constraint./main puzzles/hard_list.txt exactcover
Exact cover solver on a single hard puzzle with 17 givens:
sudoku.cppimplements the core sudoku logic and allows us to print the sudoku game to the terminalbacktrack_solver.cppimplements the backtrack solver for our Sudoku gameconstraint_solver.cppimplements the AC-3 solver for our Sudoku gameexact_cover.cppimplements Knuth's Algorithm X using Dancing Links to solve the Exact Cover problemexact_cover_solver.cppreduces the Sudoku puzzle to an exact cover problem and solves the puzzles using the implementation inexact_cover.cppmain.cppshows off our copy/move constructors and copy/move assignments. It also provides a way for us to measure the runtime of our different solvers.
- Object Oriented Programming: We represent our Sudoku Game, Sudoku Solvers, and Exact Cover as objects.
- Class hierarchy: We have an abstract Solver class for Sudoku. The solvers for our 3 different solvers will implement the Solver class and provide their methods for
void solve() - Standard Template Library (STL): We use arrays and vectors to represent the grids and subgrids in our Sudoku board.
- File IO: We allow users to input Sudoku puzzles using files and output solutions visually in the terminal.
