Skip to content

Hamza-El-Azzouzi/Sudoku

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku Solver in Go

This is a Sudoku solver implemented in Go. It uses a backtracking algorithm to efficiently solve Sudoku puzzles of varying difficulties.

Usage

To run the Sudoku solver, execute the following command in your terminal:

go run . ".96.4...1" "1...6...4" "5.481.39." "..795..43" ".3..8...." "4.5.23.18" ".1.63..59" ".59.7.83." "..359...7" | cat -e

The provided arguments represent the Sudoku puzzle rows. Each row is passed as a separate argument in the form of a string where empty cells are denoted by dots (.).

Example

Input:

.96.4...1
1...6...4
5.481.39.
..795..43
.3..8....
4.5.23.18
.1.63..59
.59.7.83.
..359...7

Output:


3 9 6 2 4 5 7 8 1$
1 7 8 3 6 9 5 2 4$
5 2 4 8 1 7 3 9 6$
2 8 7 9 5 1 6 4 3$
9 3 1 4 8 6 2 7 5$
4 6 5 7 2 3 9 1 8$
7 1 2 6 3 8 4 5 9$
6 5 9 1 7 4 8 3 2$
8 4 3 5 9 2 1 6 7$

Code Structure

The code is structured as follows:

  • Constants and Variables: Definitions of constants like gridSize and functions to print the grid, find empty locations, and check for the validity of Sudoku puzzles.
  • Sudoku Solving Algorithms: Functions for solving Sudoku puzzles, including backtracking and helper functions to check if a number is safe to place in a given position.
  • Main Function: Reads the Sudoku puzzle from command-line arguments, solves it, and prints the solution.

How It Works

The solver utilizes a backtracking algorithm to fill in the Sudoku grid recursively. It tries different numbers in empty cells and backtracks if a solution cannot be found.

Contributing

Contributions are welcome! If you have any suggestions, bug reports, or enhancements, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages