Enter your Sudoku Puzzle in the Red Box and it's Answer will appear in the Green Box

Enter Puzzle

Answer

How it Works!

An algorithm called Backtracking is used to solve this type of problems.

When the user clicks the Solve button, the values inserted by the user are stored in a 2D array. Then the program checks if the sudoku is valid. If it is invalid, a message appears saying 'Given Sudoku is invalid'. If it is valid the Recursion algorithm is called.

Now the program starts from the top-leftmost free element(i.e having value 0) and puts value '1' in it and checks if it does break the rules of Sudoku. If it breaks the rules then it increments the value byone and checks again until a valid value is assigned to that block.

After assigning a value to a block, the next block is given focus and goes through the same steps. If for a certain block, none of the value(i.e from '1' to '9') is valid then it goes back to the previous block and increments its value by one. This method of going back to the previous block is called as Backtracking.

If the value of top-leftmost free element exceeds '9', then the given problem is not Solvable and a message regarding the same is displayed. You can find the source code HERE.