GithubHelp home page GithubHelp logo

sudoku_backtracking_solution's Introduction

How to play Sudoku

Sudoku is played on a grid of 9 x 9 spaces. Within the rows and columns are 9 “squares” (made up of 3 x 3 spaces). Each row, column and square (9 spaces each) needs to be filled out with the numbers 1-9, without repeating any numbers within the row, column or square.

Apply Backtracking Algorithm

We want to avoid using the Naive Approach (try out every possible value to acquire a solution) due to having to possibly run 981 possibilities due to having a 9x9 grid with 9 possible values within in cell.

We want to use a backtracking approach to help solve this problem. The approach is as such:

  1. Pick an empty cell
  2. Try all numbers
  3. Find one that works
  4. If 3 worked, then repeat process for rest of board
  5. Backtrack as soon as a solution cannot be completed

The goal is to complete one cell at a time and recursively checking that the solutions work until you get to one that does work. This approach is a lot faster than the Naive Approach due to not having to compute 981 calculations.

Programmatic Approch

For each of the steps listed, we should be able to create an function/file dedicated for each.

  1. Create a function to find the empty cells
  2. Function to try/iterate through all numbers
  3. Check current solution/Check if the number we put in is valid
  4. Reset the value when a solution is not correct

sudoku_backtracking_solution's People

Contributors

rishirajkanungo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.