core

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidSudokuString

func IsValidSudokuString(s string) bool

Function to check if a Sudoku string is valid.

Types

type Cell

type Cell struct {
	Position Position
	Value    int
}

Define the struct for a Sudoku board cell.

func NewCell

func NewCell(position Position, value int) (cell Cell)

Constructor like function to create a new Sudoku cell. Use this when you are sure the cell is valid, will panic otherwise.

func NewCellFromInput

func NewCellFromInput(position Position, value int) (cell *Cell, err error)

Constructor like function to create a new Sudoku cell from user input. Use this to deal with user input, will return an error if the cell is invalid.

func (*Cell) IsValid

func (cell *Cell) IsValid() bool

Function to check if a cell is valid.

func (*Cell) ToString

func (cell *Cell) ToString() string

Function to print the cell as a user facing coordinate, 1-indexed.

type Position

type Position struct {
	Row    int
	Column int
}

Define the struct for a Sudoku board position.

func NewPosition

func NewPosition(row, column int) (position Position)

Constructor like function to create a new Sudoku position. Use this when you are sure the position is valid, will panic otherwise.

func NewPositionFromInput

func NewPositionFromInput(row, column int) (position *Position, err error)

Constructor like function to create a new Sudoku position from user input. Use this to deal with user input, will return an error if the position is invalid.

func (*Position) IsValid

func (position *Position) IsValid() bool

Function to check if a position is valid.

func (*Position) ToString

func (position *Position) ToString() string

Function to print the position as a user facing coordinate, 1-indexed.

type SudokuBoard

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

Define the SudokuBoard struct.

func NewEmptySudokuBoard

func NewEmptySudokuBoard() SudokuBoard

Constructor like function to create a empty Sudoku board.

func (*SudokuBoard) FilledCells

func (board *SudokuBoard) FilledCells() int

Function to get the number of filled cells.

func (*SudokuBoard) FromString

func (board *SudokuBoard) FromString(s string)

Function to build a Sudoku board from a string.

func (*SudokuBoard) Get

func (board *SudokuBoard) Get(position Position) int

Function to get the value of a position.

func (*SudokuBoard) GetRandomPositionWith

func (board *SudokuBoard) GetRandomPositionWith(validator func(int) bool) *Position

Function to get a random position satisfying the value validator.

func (SudokuBoard) IsEmpty

func (board SudokuBoard) IsEmpty() bool

Function to check if the board is empty.

func (SudokuBoard) IsSolved

func (board SudokuBoard) IsSolved() bool

Function to check if the Sudoku board is solved.

func (SudokuBoard) IsValid

func (board SudokuBoard) IsValid() bool

Function to check if the Sudoku board is valid.

func (SudokuBoard) IsValidInput

func (board SudokuBoard) IsValidInput(position Position, value int) bool

Function to check if a value can be placed in a specific position.

func (*SudokuBoard) Set

func (board *SudokuBoard) Set(position Position, value int) (err error)

Function to set the value to a position.

func (*SudokuBoard) SetCell

func (board *SudokuBoard) SetCell(cell Cell) (err error)

Function to set the value of a cell.

func (*SudokuBoard) ToString

func (board *SudokuBoard) ToString() string

Function to print the board as a single string.

func (*SudokuBoard) Unset

func (board *SudokuBoard) Unset(position Position)

Function to unset the value of a position.

Jump to

Keyboard shortcuts

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