Skip to content

Yathu2007/sudoku

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub GitHub issues GitHub pull requests GitHub forks GitHub Repo stars GitHub contributors

📘 Overview

This mini-project is to demonstrate how the backtracking algorithm can be used to solve a problem (with multiple contraints) like Sudoku. In the case of Sudoku numbers cannot repeat in a row, column or mini-grid

The process of trying possible candidates to the solution and backtracking as soon as it determines that the candidate cannot possibly be completed to a valid solution, is visible via the animation of solving.

Basic pseudocode template for sudoku backtracking

get_candidates(state) {
    return candidates // possible candidates at current state
}

solve(state) {
    if (base_case) {
        return true; // base case to return True
    } else if (another_case) {
        return solve(different_state); // several ifs for other types of cases
    } else {
        // try every possibility and backtrack when incorrect
        for candidate in get_candidates(state) {
            state.add(candidate); // modify the grid

            // recurse on the modified grid
            if (solve(state) {
                return true; // this state was solved with the chosen candidate
            } else {
                state.remove(candidate); // undo the change
            }
        }

        // tried all possible candidates,
        // but none solves the problem, so
        return false;
    }
}

Learn more in Wikipedia

🚀 Preview

🛠️ Installation Steps

  1. Clone the repository
git clone https://github.com/Yathu2007/sudoku.git
  1. Change the working directory
cd .\sudoku\
  1. Install dependencies
npm install
  1. Run the app
npm start

🌟 You are all set!

💻 Built with

About

🧩 Game of Sudoku with a solver that uses the backtracking algorithm.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published