GithubHelp home page GithubHelp logo

dassencio / sudoku Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 1.0 31 KB

A Sudoku puzzle solver which models and solves the puzzle as an integer linear programming problem.

License: GNU General Public License v3.0

Python 93.18% Shell 6.82%
sudoku linear-programming python3

sudoku's Introduction

Functional tests Static code analysis

Description

A Sudoku puzzle solver (written in Python 3) which models and solves the puzzle as an integer linear programming (ILP) problem.

License

All code from this project is licensed under the GPLv3. See the LICENSE file for more information.

Required modules

The pulp module is used. You can install it with the following command:

pip3 install pulp==2.1

Usage instructions

This projects illustrates how a Sudoku puzzle can be formulated as an integer linear programming problem. It contains two main files:

  • sudoku.py: a self-contained module with all the functionality needed to define and solve a puzzle
  • sudoku-solver: an executable script which exemplifies how sudoku.py can be used to solve a puzzle.

By default, sudoku-solver takes its input from stdin and outputs the solved puzzle on stdout. To solve a Sudoku puzzle, run ./sudoku-solver and provide the following:

  • number of rows and columns on each puzzle block in one line (e.g. 2 3)
  • for each puzzle row, a line such as _ _ _ 4 5 _ specifying the initial state of the row; initially unknown values can be represented using any non-integer character or string (e.g. _, __, ? or *)

As an example, the following input specifies a puzzle with 2ร—3 blocks, i.e., each block contains 2 rows and 3 columns, and the puzzle contains 6 rows/columns in total:

2 3
_ _ _ 2 _ _
_ _ _ 4 5 _
_ 3 4 _ _ _
_ _ _ 1 4 _
_ 6 1 _ _ _
_ _ 5 _ _ _

The output is the solution to the puzzle:

5 4 6 2 3 1
2 1 3 4 5 6
1 3 4 5 6 2
6 5 2 1 4 3
4 6 1 3 2 5
3 2 5 6 1 4

Running the functional tests

This repository comes with tests which can be used to validate the solver. These tests also illustrate the input format discussed above.

Each test contains an associated input file (e.g. test05.in) which defines the puzzle, and an associated output file (e.g. test05.out) which specifies the expected output contaning the solution to the puzzle. These files are located in the tests subdirectory. You can execute all these tests by running the run-tests script:

./run-tests

Contributors & contact information

Diego Assencio / [email protected]

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.