sudoku

package
v0.0.0-...-1e5a32e Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InferenceFunc csp.InferenceFunc = func(a *csp.Assignment, constraints []csp.Constraint, varIdx int) bool {
	toCheck := []int{varIdx}
	counter := 0

	for len(toCheck) > 0 {
		varIdx = toCheck[0]
		toCheck = toCheck[1:]
		counter++
		vi, _ := a.AssignedValue(varIdx)
		for _, c := range a.Constraints(varIdx) {
			for _, i := range c.AppliesTo() {
				if i == varIdx || a.Assigned(i) {
					continue
				}
				a.FilterDomain(i, func(valueIdx int) bool {
					return a.DomainValue(i, valueIdx) != vi
				})
				domainSize := a.DomainSize(i)
				if domainSize == 0 {
					return false
				}
				if domainSize == 1 {
					a.RangeDomain(i, func(valueIdx int) bool {
						a.Assign(i, valueIdx)
						toCheck = append(toCheck, i)
						return true
					})
				}
			}
		}
	}

	if counter < 2 {
		return true
	}
	for _, c := range constraints {
		if !c.IsSatisfied(a) {
			return false
		}
	}

	return true
}

Functions

func CreateBoardImage

func CreateBoardImage(board Board, hIdx int) image.Image

func New

func New(board Board) *csp.GenericCSP

Types

type Board

type Board []byte

func NewBoard

func NewBoard() Board

func NewBoardFromString

func NewBoardFromString(input string) Board

func (Board) IsSolved

func (b Board) IsSolved() bool

func (Board) IsValid

func (b Board) IsValid() bool

func (Board) String

func (b Board) String() string

Jump to

Keyboard shortcuts

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