This project implements a simple Sudoku solver using backtracking in C. The solver reads a Sudoku puzzle, solves it, and prints the solution along with the total steps taken to find the solution.
If you are a beginner, don't worry. You have already been provided with a basic project structure. Your task now is to manage everything, and you are allowed to modify the structure as needed.
- Features
- Installation
- Usage
- File Structure
- How It Works
- Contribution Guidelines
- General Rules
- Getting Started
- Avoiding Conflicts
- Solves a 9x9 Sudoku puzzle.
- Displays the solved Sudoku grid.
- Shows the total number of steps taken to solve the puzzle.
- Uses a simple text-based user interface.
- Clone the repository:
git clone https://github.com/clubgamma/Sudoku.git cd Sudoku
- Compile the code using GCC:
gcc main.c sudoku.c -o sudoku_solver
To run the Sudoku solver:
./sudoku_solver
To run the Sudoku solver Using txt file:
./sudoku_solver ./EXAMPLE/puz.txt
The program initializes a pre-defined Sudoku puzzle and attempts to solve it. Modify the board array in main.c to test different puzzles.
Sudoku/
├── main.c # Entry point of the Sudoku solver
├── sudoku.h # Header file containing structure and function declarations
└── sudoku.c # Implementation of Sudoku solving logic
- main.c: Contains the main function and initializes the Sudoku puzzle.
- sudoku.h: Defines the Sudoku structure and declares functions used in the solver.
- sudoku.c: Implements the logic for checking valid moves, solving the Sudoku, and printing the grid.
- The program initializes a Sudoku board with predefined values.
- It attempts to find an empty cell in the board.
- For each empty cell, it tries placing numbers from 1 to 9.
- If placing a number does not violate Sudoku rules, the program makes a recursive call to solve the rest of the board.
- If a valid solution is found, it prints the completed board and the total steps taken.
- If no solution exists, it informs the user.