Giter Site home page Giter Site logo

sudoku-solver-'s Introduction

Sudoku-Solver-

A simple Sudoku Solver based on backtracking and brute force.

Approach:

I am using a simple backtracking algorithm to brute force the solution of the grid through trial and error techqniue, the main steps are:

1- Check if the grid has an empty cell.

2- If there is an empty cell then we are not done yet, so try every possible number that can fill that cell starting from 1 all the way to 9 in each iteration, I put the value in the empty cell I have identified earlier, then I recursively call the function with the new gird i.e."the old grid+ the recently added value", the function continues and ends up with one of either possibilities:

 A) The added value fits in and a solution is found
 B) The value doesn't fit, i.e. makes it not feasible to complete 
    solving the gird, so I unmark "undo" or "remove" the added value, 
	and try another one.

3- Continue to do step 2 until I either don't find a solution or no solution at all.

Notes: 1- I think a no solution would be a result of an invalid configuration or maybe some other mathematical reason that I haven't gone deep into :V

2- The time complexity of this algorithm is exponential, but I have tried multiple problems, and my lenovo z51 takes fractions of a second to solve a normal 9X9 grid even for the most evil configurations, so I didn't feel the need to add any optimizations.

How to use:
-----------
Simply type in the grid in input.txt keeping the specified format:
1- numbers are seperated by spaces.
2- zero denotes empty cells.

Next steps: 
-----------
I may try to optimize this algorithm to run faster if needed.

sudoku-solver-'s People

Contributors

sayedalesawy avatar

Watchers

 avatar  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.