sudokugo

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

README

sudokugo

A basic Sudoku generator and solver in Go

Usage

// Generate grid
grid := sudokugo.GenerateGrid(sudokugo.VeryHard)

// Get an image of the grid
img := grid.Draw()

// Solve grid
if err := grid.Solve(); err != nil {
  // Grid could not be solved
}

Sample Sudoku Grid Output

Documentation

Index

Constants

View Source
const (
	VeryEasy = 20
	Easy     = 25
	Medium   = 35
	Hard     = 45
	VeryHard = 50
	Expert   = 60
)

Difficulties for grid generation. A difficulty level represents how many cells to clear from a fully filled grid.

Variables

View Source
var UnsolvableError = errors.New("Grid is unsolvable")

UnsolvableError is a sentinal error indicating that the grid could not be solved.

Functions

This section is empty.

Types

type Difficulty

type Difficulty int

type Grid

type Grid [9][9]uint8

A Grid is a 9x9 sudoku grid state. Grid implements the Stringer interface for pretty printing.

func GenerateGrid

func GenerateGrid(d Difficulty) *Grid

GenerateGrid returns a randomly initialized Sudoku grid for a given Difficulty.

func (Grid) Draw

func (g Grid) Draw() image.Image

Draw returns an image of the grid.

func (*Grid) Solve

func (g *Grid) Solve() error

Solve performs a backtracking algorithm to solve a given sudoku grid. If the grid cannot be solved, an UnsolvableError is returned.

func (Grid) String

func (g Grid) String() string

String implements the Stringer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL