Code Monkey home page Code Monkey logo

sudoku-solver's Introduction

Sudoku Solver

Implemented a traditional approach of pencil-and paper [1] to solve non-trivial sudoku problems. Solves n*n Grid where n>=3.

Algorithm

  • In phase one, locked all single values if any by intersecting row and columns possible values Starting with set that has lowest preemptive set.
  • If all cells are filled, then print output
  • Else try solving it by selecting a value from the subset obtained from possiblevalueList remaining cells.
  • If solution found print it
  • Else print no Solution

Note: Most of Easy and Medium problems will be solved in first phase itself.

Data Structures

  • A priority queue to store cell position and possible values.
  • A List to maintain preemptive values of each row and column.
  • A Two dimensional array to store the board.

Packages & class

  • Default Main.java: Has main method implementation.

  • Sudoku handler.java: Has the implementation of sudoku solution

    Methods

    • runSolver #sudoku.handler Does all required initialization and invokes the solution methods.

    • trySolveByLocking #sudoku.handler Has the implementation of locking single value.

    • tryRandomChoice #sudoku.handler Selects and assign a value that doesn't violate the sudoku rule from possible list to reach solution

Input

9 (grid size)

123456789 (list of symbols)

Board Values

.....9743

.5...8.1.

.1.......

8....5...

...8.4...

...3....6

.......7.

.3.5...8.

9724...5.

Restrictions

  • Only Grid with valid inputs will be allowed
  • '.' should not be given in symbols list

References

  1. Crook, J.F.. (2009). A pencil-and-paper algorithm for solving Sudoku puzzles. Notices of the American Mathematical Society. 56.

sudoku-solver's People

Contributors

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