godoku: github.com/paddie/godoku Index | Files

package godoku

import "github.com/paddie/godoku"

Package godoku is a simple, brute-force, in-place sudoku solver


Package Files


type Board Uses

type Board [][]int

type Sudoku Uses

type Sudoku struct {
    // contains filtered or unexported fields

func NewSudokuFromFile Uses

func NewSudokuFromFile(path string, dim int) (*Sudoku, error)

Load a sudoku from a path and a dimension argument

func NewSudokuFromString Uses

func NewSudokuFromString(path string, dim int) (*Sudoku, error)

Loads a sudoku-board in a string-representation; The values are in a 9x9 matrix, using space " " as delimiters and '\n' as linebreaks

func (*Sudoku) Dimension Uses

func (s *Sudoku) Dimension() int

The dimensions of the sudoku board

func (*Sudoku) GetSolution Uses

func (s *Sudoku) GetSolution() Board

GetSolution returns the solution BUG(paddie): doesn't check if board is solved

func (*Sudoku) GetSolutionsCount Uses

func (s *Sudoku) GetSolutionsCount() int

Returns the number of solutions found.

func (*Sudoku) IsSolved Uses

func (s *Sudoku) IsSolved() bool

Check if the solver has found a solution

func (*Sudoku) IsValidBoard Uses

func (s *Sudoku) IsValidBoard() bool

IsValidBoard iterates through all initial values on the board and verifies that they indeed abide by the 3 laws of Sudoku

func (*Sudoku) PrintBoard Uses

func (s *Sudoku) PrintBoard()

func (*Sudoku) Solve Uses

func (s *Sudoku) Solve() error

Solve and save the solution. Returns an error if no Sudoku has been loaded

func (*Sudoku) SolveAll Uses

func (s *Sudoku) SolveAll() error

Same as Solve, but keeps running until it has all the solutions and keeps a count. It only saves the first solution

func (*Sudoku) SolveAllAndPrint Uses

func (s *Sudoku) SolveAllAndPrint() error

Same as SolveAll but prints all the solutions to stdin

func (*Sudoku) SolveAndPrint Uses

func (s *Sudoku) SolveAndPrint() error

Same as Solve(), but this one also prints the solution to stdin

func (*Sudoku) String Uses

func (s *Sudoku) String() string

String returns either the unsolved board if the sudoku has not been solved, or the solution if such a solution has been found by running one of the Solve* methods.

func (*Sudoku) ValidInColumnAndRow Uses

func (s *Sudoku) ValidInColumnAndRow(row, col, val int) bool

Checks if _val_ already occurs in either the row or the column.

func (*Sudoku) ValidInSquare Uses

func (s *Sudoku) ValidInSquare(row, col, val int) bool

Checks that the _val_ does not already occur in the active 3x3 square

func (*Sudoku) ValidValueAtPosition Uses

func (s *Sudoku) ValidValueAtPosition(row, col, val int) bool

Verify that _val_ can be legally placed at (row,col) given restrictions in column, row and 3x3 square


doesn't check if board is solved

Package godoku imports 5 packages (graph). Updated 2016-07-29. Refresh now. Tools for package owners.