Giter Club home page Giter Club logo

sudoku's Introduction

##This is a simple Django sudoku web app. It contains:

  • Python classes that generate, solve, and check any x by x (square) sudoku puzzle.
  • UI constructed with Bootstrap and jQuery.

##Setting up the web app

  • Before you can start the app, you will need to create a private_settings.py file within base/. You will need you add a secret key as well as setting DEBUG.
  • You may also wish to setup your own database. By default this uses SQLite3. The models are quite simple so it should run on most DBs compatible with Django.
  • To seed the database; run the migrations then run python manage.py save_puzzles.py to create random puzzles and add them to the DB.

##Generating puzzles The generator will return an x by y list of lists of numbers, where 0 is an empty cell.

from common.generator import Generator

generate = Generator(9, 9)
for row in generate.generate():
    print row

Output of above:

[
    [0, 7, 8, 5, 6, 0, 1, 0, 0],
    [0, 2, 3, 0, 0, 0, 5, 7, 0],
    [0, 0, 0, 0, 0, 2, 6, 0, 0],
    [7, 0, 0, 0, 9, 1, 0, 5, 3],
    [0, 8, 0, 0, 4, 0, 0, 6, 0],
    [4, 3, 0, 6, 2, 0, 0, 0, 1],
    [0, 0, 6, 2, 0, 0, 0, 0, 0],
    [0, 4, 7, 0, 0, 0, 3, 8, 0],
    [0, 0, 1, 0, 3, 6, 7, 2, 0]
]

##Solving puzzles The solver will return a list of all the possible solutions to the puzzle. There are some examples of solving puzzles within common/runner.py.

from common.solver import Solver

raw_puzzle = [
    [0, 7, 8, 5, 6, 0, 1, 0, 0],
    [0, 2, 3, 0, 0, 0, 5, 7, 0],
    [0, 0, 0, 0, 0, 2, 6, 0, 0],
    [7, 0, 0, 0, 9, 1, 0, 5, 3],
    [0, 8, 0, 0, 4, 0, 0, 6, 0],
    [4, 3, 0, 6, 2, 0, 0, 0, 1],
    [0, 0, 6, 2, 0, 0, 0, 0, 0],
    [0, 4, 7, 0, 0, 0, 3, 8, 0],
    [0, 0, 1, 0, 3, 6, 7, 2, 0]
]
ss = Solver(raw_puzzle)
ss.solve_puzzle()
print(ss.solutions)

##Checking puzzles The checker will return True or False. True if the Puzzle is correct and False otherwise. If check_with_zeros=True, The puzzle will also return true if the puzzle is still solvable even if there are 0s left in the puzzle. There are some examples of checking puzzles within common/runner.py.

from common.solver import Solver

raw_puzzle = [
    [0, 7, 8, 5, 6, 0, 1, 0, 0],
    [0, 2, 3, 0, 0, 0, 5, 7, 0],
    [0, 0, 0, 0, 0, 2, 6, 0, 0],
    [7, 0, 0, 0, 9, 1, 0, 5, 3],
    [0, 8, 0, 0, 4, 0, 0, 6, 0],
    [4, 3, 0, 6, 2, 0, 0, 0, 1],
    [0, 0, 6, 2, 0, 0, 0, 0, 0],
    [0, 4, 7, 0, 0, 0, 3, 8, 0],
    [0, 0, 1, 0, 3, 6, 7, 2, 0]
]
ss = Solver(raw_puzzle)
ss.solve_puzzle()
print(ss.solutions)

sudoku's People

Contributors

ryannoelk avatar

Watchers

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