Giter VIP home page Giter VIP logo

sudoku-csp's Introduction

Sudoku Solver via Constraint Satisfaction

This sudoku solver expresses the puzzle as a constraint satisfaction problem. Thus, a solution is found by satisfying a set of contraints that essentially define a Sudoku puzzle.

AUTHOR

D. Pereira

MODEL 1

Creates a variable for each cell of the board, with domain equal to {1-9} if the board has a 0 at that position, and domain equal {i} if the board has a fixed number i at that cell.

Model 1 creates BINARY CONSTRAINTS OF NOT-EQUAL between all relevant variables (e.g., all pairs of variables in the same row), then invokes enforce_gac on those constraints. All of the constraints of Model_1 are binary constraints (i.e., constraints whose scope includes two and only two variables).

The ouput has the same layout as the input: a list of nine lists each representing a row of the board. However, the numbers in the positions of the input list are replaced by lists which are the corresponding cell's pruned domain (current domain) after GAC* has been performed.

MODEL 2

The variables of model 2 are the same as for model 1: a variable for each cell of the board, with domain equal to {1-9} if the board has a 0 at that position, and domain equal {i} if the board has a fixed number i at that cell.

However, model 2 has different constraints. In particular, instead of binary non-equals constaints model 2 has 27 ALL-DIFFERENT constraints: all-different constraints for the variables in each of the 9 rows, 9 columns, and 9 sub-squares. Each of these constraints is over 9-variables (some of these variables have a single value in their domain). Model 2 creates these all-different constraints between the relevant variables, then invoke enforce_gac* on those constraints.

*GAC: A variable x is generalized arc consistent (GAC) with a constraint if every value of the variable can be extended to all the other variables of the constraint in such a way the constraint is satisfied

sudoku-csp's People

Contributors

ddpereira avatar

Stargazers

Philip Kirkbride avatar Carlos Eduardo Parra avatar

Watchers

James Cloos avatar  avatar woiza 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.