solver

package
v0.0.0-...-af16e0c Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package solver provides the key functionality of this sudoku solver

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RemoveCand

func RemoveCand(cands [][][]uint8, i, j int, val uint8) (change bool)

RemoveCand removes the given value from the list of candidates for a given cell, can be used even if the value is not a candidate.

Types

type Solver

type Solver struct {
	Strats []Strategy
	Board  [][]uint8
	Cands  [][][]uint8
	Logger *log.Logger
}

Solver is the primary type for all functions. It consists of a collection of strategies to be used, the current fixed-state board (0=empty), a list ofboard candidates and a logger. The strategies will be called one at a time until one changes something, then the solver will start from the beginning.

func MakeSolver

func MakeSolver(board [][]uint8, strats []Strategy, logger *log.Logger) *Solver

MakeSolver takes a board (0s used for empty cells) and a list of strategies and creates a new solver.

func (*Solver) EnoughCands

func (sol *Solver) EnoughCands() bool

EnoughCands checks to make sure that there is at least one copy of each digit available in the list of candidates for each row/column/box.

func (*Solver) IsLegal

func (sol *Solver) IsLegal() bool

IsLegal checks the legality of the current board state of a solver, only verifies that no two copies of the same digit see each other.

func (*Solver) IsSolved

func (sol *Solver) IsSolved() bool

IsSolved checks whether the sudoku is solved (assumes that the board is in a legal state)

func (*Solver) NakedSingles

func (sol *Solver) NakedSingles() (change bool)

NakedSingles searches for naked singles and moves any that are found to the board, returns whether anything has been changed. Note: A naked single is the term for sudoku cells where there is exactly one candidate value remaining.

func (*Solver) RestrictCands

func (sol *Solver) RestrictCands() (change bool)

RestrictCands removes candidates that see a copy of the digit in the same row/column/box, returns whether anything has been changed.

func (*Solver) Solve

func (sol *Solver) Solve() bool

Solve is the main method of the solver package. This method iterates over all the provided strategies and returns true if the sudoku is uniquely solvable using those strategies, false otherwise. The solution can be accessed via sol.Board.

type Strategy

type Strategy func(*Solver) bool

Strategy is the prototype for implementing Sudoku solving strategies. As the input, each strategy receives a solver object. It is expected to perform any changes in place and return a single boolean indicating whether or not any changes have occurred.

Jump to

Keyboard shortcuts

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