Documentation ¶
Index ¶
- type Box
- func (b *Box) ColHas(c, n uint8) bool
- func (b *Box) CountEmpty() int
- func (b *Box) Empty()
- func (b *Box) GetCol(c int) []uint8
- func (b *Box) GetNumbers() []uint8
- func (b *Box) GetPos(i int) uint8
- func (b *Box) GetRow(r int) []uint8
- func (b *Box) Has(n uint8) bool
- func (b *Box) Init()
- func (b *Box) Insert(c, r, n uint8) bool
- func (b *Box) InsertPos(pos int, n uint8) bool
- func (b *Box) MarshalJSON() ([]byte, error)
- func (b *Box) RowHas(r, n uint8) bool
- func (b *Box) SetNumbers(numbers []uint8)
- type Sudoku
- func (s *Sudoku) Copy(board *Sudoku)
- func (s *Sudoku) CountEmpty() int
- func (s *Sudoku) CountSolutions() int64
- func (s *Sudoku) Fill()
- func (s *Sudoku) GeneratePuzzle() *Sudoku
- func (s *Sudoku) GetBox(idx int) *Box
- func (s *Sudoku) GetBoxFromRowCol(row int, col int) *Box
- func (s *Sudoku) GetCol(col int) []uint8
- func (s *Sudoku) GetCounter() int64
- func (s *Sudoku) GetRow(row int) []uint8
- func (s *Sudoku) Harden()
- func (s *Sudoku) HasMultipleSolutions() bool
- func (s *Sudoku) Init()
- func (s *Sudoku) IsEqual(sudoku *Sudoku) bool
- func (s *Sudoku) Print(showRich bool)
- func (s *Sudoku) Save(fileName string) error
- func (s *Sudoku) Solve() bool
- func (s *Sudoku) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct { N uint8 // contains filtered or unexported fields }
Box defines the strucure of each box in a Sudoku puzzle.
func (*Box) CountEmpty ¶
CountEmpty returns the amount of empty cells.
func (*Box) GetNumbers ¶
GetNumbers returns a copy of the numbers in the box.
func (*Box) Init ¶
func (b *Box) Init()
Init initializes the numbers array and numbers map. This needs to be run before anything else runs.
func (*Box) MarshalJSON ¶
MarshalJSON is used by the JSON module to tell it how the JSON format looks like.
type Sudoku ¶
type Sudoku struct { // Figure out the logic here. Ideally we want them to add // as many as they want, but currently the logic below is // just for 9 (the typical). N uint8 `json:"n"` // The number of columns and rows. Seed int64 `json:"seed"` Board []*Box `json:"board"` // contains filtered or unexported fields }
Sudoku defines the structure of the entire Sudoku board.
func ParseBoard ¶
ParseBoard parses a valid sudoku board. Empty slots are represented with a ".". Slots are printed from the first 3x3 grid all the way to the last one. [1] [2] [3] [4] [5] [6] [7] [8] [9] And the numbers within each 3x3 box are placed in the same order as the 3x3 boxes.
func (*Sudoku) CountEmpty ¶
CountEmpty returns the total number of empty cells in the puzzle.
func (*Sudoku) CountSolutions ¶
CountSolutions returns the total amount of solutions for this board.
func (*Sudoku) GeneratePuzzle ¶
GeneratePuzzle needs to run after `Fill`. It generates a proper puzzle with some indecies which are hidden. TODO: Start from scratch.
func (*Sudoku) GetBoxFromRowCol ¶
GetBoxFromRowCol returns the box from a specific point in the board.
func (*Sudoku) GetCounter ¶
GetCounter returns the number of itterations on the specific board.
func (*Sudoku) Harden ¶
func (s *Sudoku) Harden()
Harden itterates over the existing puzzle (after calling `GeneratePuzzle`), or board (after calling `Fill` - albeit the results would not be that great) and empties cells randomly until it gets the hardest solvable puzzle only with one solution. This algorithm implements backtracking, similar to `Solve`, but it empties cells until it's reached a difficulty that we want.
func (*Sudoku) HasMultipleSolutions ¶
HasMultipleSolutions returns true if there are multiple solutions, or false if there is only one.
func (*Sudoku) Init ¶
func (s *Sudoku) Init()
Init initializes the Sudoku instance. It's required before running `Fill`.