models

package
v0.0.0-...-d69d8d0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BitsIndexes

func BitsIndexes(n uint16) []int

Bits indexes return the 0 base index of every '1' in the base 2 representation of n

func BoxCoordToGridIndex

func BoxCoordToGridIndex(box int, pos int) int

func CoordToBox

func CoordToBox(r int, c int) int

CoordToBox turns sudoku grid coordinates into the coresponding block number

func IndexToCoord

func IndexToCoord(i int) (int, int)

IndexToCoord turns an index in [0, 80] to its sudoku grid row , col coordinates in [0, 8]

func IsolatedBitIndex

func IsolatedBitIndex(n uint16) (int, bool)

IsolatedBitIndex checks if a uint16 is composed of only a single 1 (i.e n is a power of 2) and returns either (-1, false) if it isn't otherwise it's base 1 index and true. (log2(n), true)

Types

type Cell

type Cell struct {
	// contains filtered or unexported fields
}

func NewCell

func NewCell() Cell

NewCell creates an empty Cell with all possible candidates

func (Cell) GetCandidates

func (c Cell) GetCandidates() uint16

GetCandidates returns the Cell's candidates

func (*Cell) HasCandidate

func (c *Cell) HasCandidate(n int) bool

HasCandidate checks if the Cell has the candidate {n}

func (*Cell) HasNoCandidate

func (c *Cell) HasNoCandidate() bool

HasNoCandidates returns true if there is no possible candidate for this Cell (i.e invalid grid)

func (Cell) HasOneCandidate

func (c Cell) HasOneCandidate() (int, bool)

HasOneCandidate check if a Cell has only one candidate possible and returns it if it exists

func (Cell) IsSet

func (c Cell) IsSet() bool

IsSet return true if the Cell has a value and false otherwise

func (*Cell) RemoveCandidate

func (c *Cell) RemoveCandidate(n int)

RemoveCandidate removes the candiates {n} from the possible candidates

func (*Cell) RemoveCandidateExcept

func (c *Cell) RemoveCandidateExcept(digits ...int) bool

RemoveCandidateExcept removes all candidates except the ones listed in the arguments

func (*Cell) RemoveCandidateWithFeedback

func (c *Cell) RemoveCandidateWithFeedback(n int) bool

RemoveCandidateWithFeedback removes the candiates {n} from the possible candidates returs true if a value was removed, false if the value was already removed

func (*Cell) SetCandidates

func (c *Cell) SetCandidates(cand uint16)

SetCandiates forces the candidates values, this only serves testing purposes, do not use

type DigitsPositionsMasks

type DigitsPositionsMasks struct {
	Rows  [][]uint16
	Cols  [][]uint16
	Boxes [][]uint16
}

type Grid

type Grid struct {
	Grid  []Cell
	Rows  [][]*Cell
	Cols  [][]*Cell
	Boxes [][]*Cell

	DigitsPositions DigitsPositionsMasks
}

func NewGrid

func NewGrid(s string) (*Grid, error)

func (*Grid) InsertNumberByCoord

func (g *Grid) InsertNumberByCoord(n int, row int, col int)

func (*Grid) InsertNumberByIndex

func (g *Grid) InsertNumberByIndex(n int, index int)

func (Grid) IsFilled

func (g Grid) IsFilled() bool

func (Grid) IsValid

func (g Grid) IsValid() bool

func (Grid) Print

func (g Grid) Print()

func (Grid) String

func (g Grid) String() string

func (*Grid) UpdateDigitsPositionMask

func (g *Grid) UpdateDigitsPositionMask()

UpdateDigitsPositionMask creates a map with 3 keys (rows,cols,boxes) each element contains a 2D array of uint16. The first dimension correspond to the set number (row 1, col3...) the second dimension correspond to a sudoku number (base 0) for witch you want the mask in the row ex: row[0][4] = 0b100100100 means that in row 1, the 5 could be in positions 3,6 or 9

Jump to

Keyboard shortcuts

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