Coder Social home page Coder Social logo

siraben / sudoku Goto Github PK

View Code? Open in Web Editor NEW

This project forked from coq-community/sudoku

0.0 2.0 0.0 395 KB

A certified Sudoku solver

License: GNU Lesser General Public License v2.1

Coq 93.70% Makefile 0.16% CSS 0.11% HTML 1.46% JavaScript 3.12% OCaml 1.46%

sudoku's Introduction

Sudoku

Docker CI Nix CI Contributing Code of Conduct Zulip

A formalisation of Sudoku in Coq. It implements a naive Davis-Putnam procedure to solve Sudokus.

Meta

Building and installation instructions

The easiest way to install the latest released version of Sudoku is via OPAM:

opam repo add coq-released https://coq.inria.fr/opam/released
opam install coq-sudoku

To instead build and install manually, do:

git clone https://github.com/coq-community/sudoku.git
cd sudoku
make   # or make -j <number-of-cores-on-your-machine> 
make install

Documentation

A Sudoku is represented as a mono-dimensional list of natural numbers. Zeros are used to represent empty cells. For example, the 3x3 Sudoku:

  -------------------------------------
  |   |   | 8 | 1 | 6 |   | 9 |   |   |
  -------------------------------------
  |   |   | 4 |   | 5 |   | 2 |   |   |
  -------------------------------------
  | 9 | 7 |   |   |   | 8 |   | 4 | 5 |
  -------------------------------------
  |   |   | 5 |   |   |   |   |   | 6 |
  -------------------------------------
  | 8 | 9 |   |   |   |   |   | 3 | 7 |
  -------------------------------------
  | 1 |   |   |   |   |   | 4 |   |   |
  -------------------------------------
  | 3 | 6 |   | 5 |   |   |   | 8 | 4 |
  -------------------------------------
  |   |   | 2 |   | 7 |   | 5 |   |   |
  -------------------------------------
  |   |   | 7 |   | 4 | 9 | 3 |   |   |
  -------------------------------------

is represented as

  0 :: 0 :: 8 :: 1 :: 6 :: 0 :: 9 :: 0 :: 0 ::
  0 :: 0 :: 4 :: 0 :: 5 :: 0 :: 2 :: 0 :: 0 ::
  9 :: 7 :: 0 :: 0 :: 0 :: 8 :: 0 :: 4 :: 5 ::
  0 :: 0 :: 5 :: 0 :: 0 :: 0 :: 0 :: 0 :: 6 ::
  8 :: 9 :: 0 :: 0 :: 0 :: 0 :: 0 :: 3 :: 7 ::
  1 :: 0 :: 0 :: 0 :: 0 :: 0 :: 4 :: 0 :: 0 ::
  3 :: 6 :: 0 :: 5 :: 0 :: 0 :: 0 :: 8 :: 4 ::
  0 :: 0 :: 2 :: 0 :: 7 :: 0 :: 5 :: 0 :: 0 ::
  0 :: 0 :: 7 :: 0 :: 4 :: 9 :: 3 :: 0 :: 0 :: nil

All functions are parametrized by the height and width of a Sudoku's subrectangles. For example, for a 3x3 Sudoku:

sudoku 3 3: list nat -> Prop

check 3 3: forall l, {sudoku 3 3 l} + {~ sudoku 3 3 l}

find_one 3 3: list nat -> option (list nat)

find_all 3 3: list nat -> list (list nat)

See Test.v.

Corresponding correctness theorems are:

find_one_correct 3 3
     : forall s,
       length s = 81 ->
       match find_one 3 3 s with
       | Some s1 => refine 3 3 s s1 /\ sudoku 3 3 s1
       | None =>
           forall s, refine 3 3 s s1 -> ~ sudoku 3 3 s1
       end

find_all_correct 3 3
     : forall s s1, refine 3 3 s s1 -> (sudoku 3 3 s1 <-> In s1 (find_all 3 3 s))

See Sudoku.v.

More about the formalisation can be found in a note.

The following files are included:

  • ListOp.v some basic functions on list
  • Sudoku.v main file
  • Test.v test file
  • Tactic.v contradict tactic
  • Div.v division and modulo for nat
  • Permutation.v permutation
  • UList.v unique list
  • ListAux.v auxillary facts on lists
  • OrderedList.v ordered list

The Sudoku code can be extracted to JavaScript using js_of_ocaml:

make Sudoku.js

Then, point your browser at Sudoku.html.

sudoku's People

Contributors

palmskog avatar siraben avatar thery avatar herbelin avatar letouzey avatar ppedrot avatar

Watchers

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