Giter Site home page Giter Site logo

sudoku-solver's Introduction

sudoku-solver

wercker status Coverage Status Go Report Card

A simple golang sudoku solver using Peter Norvig algorithm

Installation

$ go get github.com/laurentlp/sudoku-solver

To install the dependencies (Tests + API)

Install glide (Package Management for Golang)

$ curl https://glide.sh/get | sh

Or via Homebrew on MacOS

$ brew install glide

Then to install the dependencies the dependencies

$ glide i

Running the tests

Test the solver

$ cd $GOPATH/src/github.com/laurentlp/sudoku-solver
$ go test -v ./solver

Test everything

Simply run the test.sh file like so

$ cd $GOPATH/src/github.com/laurentlp/sudoku-solver
$ ./test.sh

*Before, make sure the file is executable

$ chmod 777 test.sh

API

To use the API, simply run the main.go file in the command line. Then enter your sudoku in the body of the request as shown bellow :

Make a POST request to http://localhost:8080/sudoku

with the body (JSON) :

{
    "sudoku" : "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......"
}

Result :

solved.jpg from the examples folder

Basic usage of the solver

First create a separate go project in which you will need a main.go file

package main

import (
    "fmt"

    "github.com/laurentlp/sudoku-solver/solver"
)

func main() {
    // Directly write a sudoku grid or use a file as shown in the examples folder
    grid := "4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......"
    resolved, err := solver.Solve(grid)

    if err != nil {
        fmt.Print(err)
    }

    solver.Display(resolved)
}

Now to run the file just hit go run main.go in the command line at the root of your project.

You should see an output looking like this :

$ go run main.go

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

sudoku-solver's People

Contributors

laurentlp avatar

Stargazers

 avatar

Watchers

 avatar  avatar

sudoku-solver's Issues

[Enhancement] Make separate tests for the API

Steps :

  • Look for tests frameworks or simply use testing library
    --> github.com/smartystreets/goconvey/convey
  • Make tests that cove at least 80% of the whole API
    - [ ] Make separate testing steps with Wercker
    All tests are in one execution ! Code coverage too !

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.