GithubHelp home page GithubHelp logo

aind-sudoku's Introduction

Artificial Intelligence Nanodegree

Introductory Project: Diagonal Sudoku Solver

In this project we will go over the solution to solve sudoku using naked-twin strategy. Further we will extend the solution to solve for diagonal sudoku where the diagonals of the board are constraint to have all the numbers between 1 and 9. To test the solution, run

python solution_test.py

To test solution, run

python solution.py

Diagonal soduku solution using eliminate, naked-twins and only-choice strategy

Question 1 (Naked Twins)

Q: How do we use constraint propagation to solve the naked twins problem?
A: Constraint propagation is the idea of applying the same constraint as many times as possible until a solution is obtained, or the constraint can no longer be applied to refine the solution.

In sudoku, we apply naked twins as a strategy to reduce the number of possibilities. Naked twins is the strategy is illustrated in the figure below. The strategy is to identify a pair of boxes belonging to the same set of peers that have the same 2 numbers as possibilities, and eleminate these two numbers from all the boxes that have these two boxes as peers.

This method was implemented in Python using a set intersection function. First we identify all boxes that have only 2 elements. Next we identify which boxes among these have the same elements to get naked twins. Once we get the naked twins, we remove the corresponding digits from all the boxes that are peers to both the twins. This is illustrated in the code snippet below.

We use naked_twins in conjunction with eliminate and only-choice to reduce the number of possibilities as shown in the reduce_puzzle snippet below.

Question 2 (Diagonal Sudoku)

Q: How do we use constraint propagation to solve the diagonal sudoku problem?
A: For diagonal sudoku, the easiest way to incorporate diagonal contraint was to include it as an additional unit in sudoku. Once this is done, all the diagonal entries will have the corresponding diagonal entries as their peers. This will result in not accepting solutions that do not satisfy the diagonal constraint. The code snippet below presents the method of implementing diagonal constraint.

aind-sudoku's People

Contributors

vxy10 avatar

Watchers

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