utils

package
v0.0.0-...-84f8b02 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	East      = Direction{0, 1}
	North     = Direction{-1, 0}
	NorthEast = Direction{-1, 1}
	NorthWest = Direction{-1, -1}
	South     = Direction{1, 0}
	SouthEast = Direction{1, 1}
	SouthWest = Direction{1, -1}
	West      = Direction{0, -1}

	AzimuthDirections = []Direction{North, East, South, West}
	AllDirections     = []Direction{North, NorthEast, East, SouthEast, South, SouthWest, West, NorthWest}

	SymbolDirectionIdx = map[byte]int{
		'^': 0,
		'>': 1,
		'v': 2,
		'<': 3,
	}
)

Functions

func CreateMatrix

func CreateMatrix(height, width int, ch byte) [][]byte

func DuplicateBytesMatrix

func DuplicateBytesMatrix(in [][]byte) [][]byte

func Int

func Int(s string) int

func IntsToStrings

func IntsToStrings(ints []int) []string

func Positions

func Positions(in [][]byte) iter.Seq[Pos]

func PositionsForHeightWidth

func PositionsForHeightWidth(height, width int) iter.Seq[Pos]

func PositionsValues

func PositionsValues(in [][]byte) iter.Seq2[Pos, byte]

func PrintMatrix

func PrintMatrix(in [][]byte)

func ReadFileIntoBytesMatrix

func ReadFileIntoBytesMatrix(file io.Reader) ([][]byte, error)

func RepeatInt

func RepeatInt(value int, count int) []int

func ScanFileLineByLine

func ScanFileLineByLine(file io.Reader, cb func(line string)) error

func StringsToInts

func StringsToInts(ss []string) []int

Types

type Direction

type Direction [2]int

Direction represents the irreverence in Y and X

func (Direction) X

func (d Direction) X() int

func (Direction) Y

func (d Direction) Y() int

type IntHeap

type IntHeap []int

func InitIntHeap

func InitIntHeap(nums []int) IntHeap

func (IntHeap) Len

func (h IntHeap) Len() int

func (IntHeap) Less

func (h IntHeap) Less(i, j int) bool

func (*IntHeap) Pop

func (h *IntHeap) Pop() any

func (*IntHeap) Push

func (h *IntHeap) Push(x any)

func (IntHeap) Swap

func (h IntHeap) Swap(i, j int)

type Pos

type Pos [2]int

func NewPos

func NewPos(y, x int) Pos

func WhereIs

func WhereIs(in [][]byte, what byte) Pos

func (Pos) Eq

func (p Pos) Eq(v Pos) bool

func (Pos) InBoundaries

func (p Pos) InBoundaries(height, width int) bool

func (Pos) Next

func (p Pos) Next(d Direction) Pos

func (Pos) Values

func (p Pos) Values() (int, int)

func (Pos) X

func (p Pos) X() int

func (Pos) Y

func (p Pos) Y() int

type Queue

type Queue []*Step

Queue (see `container/heap`

func (Queue) Len

func (pq Queue) Len() int

func (Queue) Less

func (pq Queue) Less(i, j int) bool

func (*Queue) Pop

func (pq *Queue) Pop() interface{}

func (*Queue) Push

func (pq *Queue) Push(x interface{})

func (Queue) Swap

func (pq Queue) Swap(i, j int)

type Step

type Step struct {
	St StepState
	S  int // Score
}

type StepState

type StepState struct {
	P Pos
	D int // just an index of Azimuth directions
}

Jump to

Keyboard shortcuts

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