Documentation ¶
Index ¶
- Constants
- Variables
- func BackTrack(data [BoardSize][BoardSize]*Cell) (bool, [BoardSize][BoardSize]*Cell)
- func BitmapPairs(in []uint32) []*roaring.Bitmap
- func BitmapQuads(in []uint32) []*roaring.Bitmap
- func BitmapSingles(in []uint32) []*roaring.Bitmap
- func BitmapTriplets(in []uint32) []*roaring.Bitmap
- func CloneData(data [BoardSize][BoardSize]*Cell) [BoardSize][BoardSize]*Cell
- func ColumnsHasAtLeast2TimesTheValue(up *roaring.Bitmap, middle *roaring.Bitmap, down *roaring.Bitmap) bool
- func EliminateHiddenPairs(units [][]*Cell) error
- func EliminateHiddenQuads(units [][]*Cell) error
- func EliminateHiddenSingles(units [][]*Cell) error
- func EliminateHiddenTriplets(units [][]*Cell) error
- func EliminateNakedPairs(units [][]*Cell) error
- func EliminateNakedQuads(units [][]*Cell) error
- func EliminateNakedTriplets(units [][]*Cell) error
- func EliminateSwordFish(b *Board) error
- func EliminateXWings(b *Board) error
- func EliminateXYWings(unsolved []*Cell, b *Board) error
- func EliminateXYZWings(unsolved []*Cell, b *Board) error
- func FindMarksOfUnit(unit []*Cell) *roaring.Bitmap
- func IndexesBitmap(cells []*Cell) *roaring.Bitmap
- func IsCellInCollection(cell *Cell, collection []*Cell) bool
- func IsCellInCollections(cell *Cell, collection [][]*Cell) bool
- func IsCombinationHiddenWithinUnit(bitmap *roaring.Bitmap, cells []*Cell, unit []*Cell) bool
- func IsHiddenPair(pair []*Cell, unit []*Cell) (bool, *roaring.Bitmap)
- func IsHiddenQuad(quad []*Cell, unit []*Cell) (bool, *roaring.Bitmap)
- func IsHiddenSingle(single *Cell, unit []*Cell) (bool, *roaring.Bitmap)
- func IsHiddenTriplet(triplet []*Cell, unit []*Cell) (bool, *roaring.Bitmap)
- func IsPairRelated(pair []*Cell, board *Board) bool
- func IsSolved(data [BoardSize][BoardSize]*Cell) (bool, int, int)
- func IsTripletHasSameCardinality(triplet []*Cell, cardinality int) bool
- func IsTripletUnionHasCardinality(triplet []*Cell, cardinality int) bool
- func IsTripletXYZWingBasedOnCardinality(triplet []*Cell) bool
- func IsValidBuffer(buffer []byte) bool
- func IsValidValue(data [BoardSize][BoardSize]*Cell, row int, col int, value Value) bool
- func PairCombinations(input []*Cell) [][]*Cell
- func ParIntersect(units ...*roaring.Bitmap) *roaring.Bitmap
- func ParIntersectCells(cells []*Cell) *roaring.Bitmap
- func ParUnion(units ...*roaring.Bitmap) *roaring.Bitmap
- func ParUnionCells(cells []*Cell) *roaring.Bitmap
- func QuadCombinations(input []*Cell) [][]*Cell
- func SolvedCells(cells []*Cell) *roaring.Bitmap
- func TripletCombinations(input []*Cell) [][]*Cell
- type Board
- type Cell
- func Box(data [BoardSize][BoardSize]*Cell, rowID int, colID int) []*Cell
- func Col(data [BoardSize][BoardSize]*Cell, index int) []*Cell
- func HasSwordFishCandidates(row []*Cell) (bool, []*Cell, *roaring.Bitmap)
- func HasXCandidates(row []*Cell) (bool, []*Cell, *roaring.Bitmap)
- func HiddenPairs(unit []*Cell) (bool, []*Cell, *roaring.Bitmap)
- func HiddenQuads(unit []*Cell) (bool, []*Cell, *roaring.Bitmap)
- func HiddenSingles(unit []*Cell) (bool, *Cell, *roaring.Bitmap)
- func HiddenTriplets(unit []*Cell) (bool, []*Cell, *roaring.Bitmap)
- func IsMarkAppearsTwiceInRow(mark *roaring.Bitmap, row []*Cell) (bool, []*Cell)
- func IsMarkAppearsTwiceOrThreeInRow(mark *roaring.Bitmap, row []*Cell) (bool, []*Cell)
- func IsNakedPairs(combinations [][]*Cell) (bool, []*Cell)
- func IsNakedQuad(combinations [][]*Cell) (bool, []*Cell)
- func IsNakedTriplet(combinations [][]*Cell) (bool, []*Cell)
- func Row(data [BoardSize][BoardSize]*Cell, index int) []*Cell
- func SearchSwordFishMiddlePart(upCells []*Cell, mark *roaring.Bitmap, rowIndex int, b *Board) (bool, []*Cell, int)
- func UnSolvedCells(cells []*Cell) []*Cell
- type Difficulty
- type SolveResponse
- type Strategy
- type SwordFish
- type Value
- type XWing
- type XYWing
- type XYZWing
Constants ¶
const ( BoardSize = 9 BlockSize = 3 EmptyCellValue = Value(0) MinimumGivens = 17 Offset = 1 EOL = 0x0A )
Variables ¶
var Digits = roaring.BitmapOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
var HexMap = map[byte]Value{
0x2e: 0x00,
0x30: 0x00,
0x31: 0x01,
0x32: 0x02,
0x33: 0x03,
0x34: 0x04,
0x35: 0x05,
0x36: 0x06,
0x37: 0x07,
0x38: 0x08,
0x39: 0x09,
}
var Levels = map[Difficulty]string{ Easy: "Easy", Medium: "Medium", Hard: "Hard", Expert: "Expert", Evil: "Evil", }
var ValidInputs = roaring.BitmapOf(uint32(EmptyCellValue), 1, 2, 3, 4, 5, 6, 7, 8, 9)
Functions ¶
func BitmapPairs ¶
BitmapPairs simply creates all unique ordered pair combinations in given uint32 array as roaring.Bitmap instance
func BitmapQuads ¶
BitmapQuads simply creates all unique ordered quad combinations in given uint32 array as roaring.Bitmap instance
func BitmapSingles ¶
BitmapSingles simply creates all unique ordered single combinations in given uint32 array as roaring.Bitmap instance
func BitmapTriplets ¶
BitmapTriplets simply creates all unique ordered triplet combinations in given uint32 array as roaring.Bitmap instance
func EliminateHiddenPairs ¶
EliminateHiddenPairs eliminates the marks from the pairs which has exactly and only the same two candidates all over the unit. The other candidates could be removed safely from the pairs
func EliminateHiddenQuads ¶
func EliminateHiddenSingles ¶
func EliminateHiddenTriplets ¶
EliminateHiddenTriplets eliminates the marks from the pairs which has exactly and only the same two candidates all over the unit. The other candidates could be removed safely from the pairs
func EliminateNakedPairs ¶
EliminateNakedPairs creates pairs combinations of marks/candidates on each unit (row, col or box) if there are any pairs having the cardinality 2 (Unions of the three sets has exactly 2 different elements) Then the other cell candidates within the unit having one of these elements is safely eliminated Returns the number of eliminated candidates
func EliminateNakedQuads ¶
EliminateNakedQuads creates quad combinations of marks/candidates on each unit (row, col or box) if there are any quads having the cardinality 4 (Unions of the three sets has exactly 4 different elements) Then the other cell candidates within the unit having one of these elements is safely eliminated Returns the number of eliminated candidates
func EliminateNakedTriplets ¶
EliminateNakedTriplets creates triple combinations of marks/candidates on each unit (row, col or box) if there are any triplets having the cardinality 3 (Unions of the three sets has exactly 3 different elements) Then the other cell candidates within the unit having one of these elements is safely eliminated
func EliminateSwordFish ¶
func EliminateXWings ¶
func EliminateXYWings ¶
func EliminateXYZWings ¶
func FindMarksOfUnit ¶
FindMarksOfUnit finds marks/candidates of the given unit by getting the difference (XOR) of solved cells and all available digits
func IndexesBitmap ¶
func IsCellInCollection ¶
IsCellInCollection is a helper function to report whether given cell is inside of collection or not
func IsCellInCollections ¶
IsCellInCollections is a helper function to report whether given cell is inside of collections or not
func IsHiddenPair ¶
IsHiddenPair is a helper method to calculate the intersection of the giving pair and looping over the unit to get the diff of intersection and other cell marks, and if the final intersection of difference have some elements, then the given pair is a hidden pair. Function returns also the marks that has to be kept
func IsHiddenTriplet ¶
IsHiddenTriplet is a helper method to calculate the intersection of the giving pair and looping over the unit to get the diff of intersection and other cell marks, and if the final intersection of difference have some elements, then the given pair is a hidden pair. Function returns also the marks that has to be kept
func IsPairRelated ¶
func IsValidBuffer ¶
IsValidBuffer simply checks whether the current buffer holds valid board information or not
func IsValidValue ¶
func PairCombinations ¶
PairCombinations simply creates all unique ordered pair combinations of given cell unit
func ParIntersect ¶
ParIntersect returns the intersection of all given units
func ParIntersectCells ¶
ParIntersectCells returns the intersection of all given cells
func ParUnionCells ¶
ParUnionCells returns the union of all given cells
func QuadCombinations ¶
QuadCombinations simply creates all unique ordered quad combinations of given cells unit
func SolvedCells ¶
SolvedCells creates marks from the solved cells within the unit
func TripletCombinations ¶
TripletCombinations simply creates all unique ordered triple combinations of given cells unit
Types ¶
type Board ¶
type Board struct {
// contains filtered or unexported fields
}
Board is the struct of the Sudoku board
func NewBoard ¶
NewBoard returns new Sudoku board with the given input matrix, if there are any issues it also returns error
func (*Board) GetGivensAndBackTrack ¶
GetGivensAndBackTrack returns the givens and backTrackUsed flag
func (*Board) Solve ¶
func (b *Board) Solve() *SolveResponse
Solve is a utility function to start the solving process of given sudoku board
type Cell ¶
Cell is the struct of cell keeping unique id, row and col ids solved value and current marks/candidates
func HasSwordFishCandidates ¶
func HiddenPairs ¶
HiddenPairs is a helper method to find any hidden pair over the unit by creating pair combinations and testing the pairs whether they are hidden pair or not
func HiddenTriplets ¶
HiddenTriplets is a helper method to find any hidden pair over the unit by creating triplet combinations and testing the triplets whether they are hidden triplet or not
func IsMarkAppearsTwiceInRow ¶
func IsNakedPairs ¶
IsNakedPairs simply checks whether there are any naked pairs or not in the given combination
func IsNakedQuad ¶
IsNakedQuad simply checks whether there are any naked quads or not in the given combination
func IsNakedTriplet ¶
IsNakedTriplet simply checks whether there are any naked triplets or not in the given combination
func UnSolvedCells ¶
UnSolvedCells returns the unsolved cells within the unit
func (*Cell) ComputeCellMarks ¶
ComputeCellMarks computes the candidates/marks of the current cell
func (*Cell) MarksLength ¶
MarksLength simply returns the length of the current marks bitmap
type SolveResponse ¶
type SolveResponse struct { Difficulty string Givens int InitialState string Solution string Duration float64 IsSolved bool BackTrackingUsed bool StrategiesUsed []string Error error }
func (*SolveResponse) Print ¶
func (r *SolveResponse) Print() string
type Strategy ¶
type Strategy string
const ( NakedQuadsStrategy Strategy = "Naked Quads" NakedTriplesStrategy Strategy = "Naked Triples" NakedPairsStrategy Strategy = "Naked Pairs" XYWingsStrategy Strategy = "XY Wings" XYZWingsStrategy Strategy = "XYZ Wings" XWingsStrategy Strategy = "X Wings" SwordFishStrategy Strategy = "Sword Fish" HiddenSingleStrategy Strategy = "Hidden Single" HiddenQuadsStrategy Strategy = "Hidden Quads" HiddenTripletsStrategy Strategy = "Hidden Triplets" HiddenPairsStrategy Strategy = "Hidden Pairs" )