Giter Site home page Giter Site logo

royveshovda / aind-p1-sudoku Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 174 KB

Part of Artificial Intelligence Nanodegree (AIND) from Udacity. First project in Term 1 trying to solve Sudoku.

Home Page: https://www.udacity.com/ai

Python 100.00%
aind

aind-p1-sudoku's Introduction

Artificial Intelligence Nanodegree

Introductory Project: Diagonal Sudoku Solver

Question 1 (Naked Twins)

  • Q: How do we use constraint propagation to solve the naked twins problem?
  • A: Naked twins strategy looks for boxes with similar pairs inside the same unit. If two such pairs (for example 23) is found inside the same unit, we know that the values (23) has to be in thos two boxes. We therefore remove the values from all the other boxes in that unit. It is important to note that this has to be process on one unit at the time.

The function (naked_twins) first looks for all boxes with only two values inside. The function then iterates over these boxes, finds all units the current box is a member of. Now having a box and a unit, the function looks for identical boxes. I a match is found, the boxes are called naked twins, and the values of this naked twins can be removed from all other boxes in the current unit.

One important note to make is that it is tempting to detect pairs in all boxes, and flag them as candidates, and process through them one at the time. My first attempt did just this. It is important to chech if the box previously flagged as pair, can have been pruned down to a single value in an earlier naked twin detection. A last check if the box is still a pair is important.

The naked_twins function is a constraining function which is called in from the solved function at the same time as the other constraining functions (eliminate and only_choice). I included the function inside the solution from the class, only having to implement the function, and include it inside the already working "solve" function.

Question 2 (Diagonal Sudoku)

  • Q: How do we use constraint propagation to solve the diagonal sudoku problem?
  • A: In the code from the class the strategy is to apply different constraint propagations one unit at a time. To solve the diagonal sudoku problem, we need to add two more units. One going from the upper left down to the lower right, and one from upper right down to lower left. In the code these are called "diagonal_units", and are hard coded (as there are only two of them). These diagonal units are then included with all the other units, and used in all the constrating functions (including the one from question 1) to solve the sudoku problem.

General

I based both additions on the code used during the lecture. This was a great foundation which only required to add constraints as described above. Being able to implement these new strategies this easy, is an indication that the foundation from class is a very good model for the sudoku problem.

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.