Documentation
¶
Overview ¶
Package aoc provides utility functions and types to assist with solving Advent of Code puzzles and other similar algorithmic challenges.
It includes:
- Input reading and parsing utilities
- Simple output formatting (for 2D arrays)
- Coordinate manipulation (type Coord)
- Saving 2D byte arrays as images
Example usage:
input := aoc.ReadInputInt()
sum := 0
for _, value := range input {
sum += value
}
coord := aoc.Coord{X: 0, Y: 0}
upper := coord.Up()
caveMap := aoc.ReadInputBytes()
aoc.SaveBytesImage("output.ppm", caveMap, map[byte]int{
'.': 0xFFFFFF,
'#': 0x000000,
})
This package aims to provide fast and simple helpers for common Advent of Code tasks, minimizing boilerplate code.
Index ¶
- func AtCoord[E any](area [][]E, coord Coord) E
- func AtCoordUnlimited[E any](area [][]E, coord Coord, defaultValue E) E
- func Boundaries(coords []Coord) (Coord, Coord)
- func CountIf[S any](s []S, f func(S) bool) int
- func Distance(coord1, coord2 Coord) int
- func GetRunType() string
- func Grid2D(startx, endx, starty, endy int) iter.Seq2[int, int]
- func GridCoords(tl, br Coord) iter.Seq[Coord]
- func ParseInt(input []string) []int
- func ParseIntList(input []string) [][]int
- func ParseLineIntList(line string) []int
- func ParseLineSplit(input string, delimiter string) []string
- func ParseSplit(input []string, delimiter string) [][]string
- func Prod[E mulable](s []E) E
- func ProdFunc[S any, E mulable](s []S, f func(e S) E) E
- func ProdSeq[E mulable](seq iter.Seq[E]) E
- func ReadInput() []string
- func ReadInputBytes() [][]byte
- func ReadInputInt() []int
- func ReadInputIntList() [][]int
- func ReadInputLine() string
- func ReadInputLineIntList() []int
- func ReadInputLineSplit(delimiter string) []string
- func ReadInputSplit(delimiter string) [][]string
- func SaveBytesImage(filename string, image [][]byte, colors map[byte]int)
- func SetAtCoord[E any](area [][]E, coord Coord, val E)
- func ShowBytesCondensed(area [][]byte)
- func ShowIntsCondensed(area [][]int)
- func ShowIntsCsv(area [][]int)
- func ShowResult(values ...any)
- func Sum[E addable](s []E) E
- func SumFunc[S any, E addable](s []S, f func(e S) E) E
- func SumSeq[E addable](seq iter.Seq[E]) E
- func Transpose(lines []string) []string
- type Coord
- func (coord Coord) AllNeighbours() []Coord
- func (coord Coord) AllNeighbours8() []Coord
- func (coord Coord) Down() Coord
- func (coord Coord) Left() Coord
- func (coord Coord) Neighbours(width, height int) []Coord
- func (coord Coord) Neighbours8(width, height int) []Coord
- func (coord Coord) Right() Coord
- func (coord Coord) Up() Coord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtCoordUnlimited ¶ added in v1.1.0
AtCoordUnlimited returns the value found at coordinate of the given area and default value if the area does not contain the coordinate
func Boundaries ¶ added in v1.3.0
Boundaries returns the top left corner and the bottom right corner of the smallestboundary box containing each coordinates
func CountIf ¶ added in v1.6.0
CountIf returns the number of elements in s which pass the f test funvtion
func GetRunType ¶
func GetRunType() string
func Grid2D ¶ added in v1.5.0
Grid2D returns an iterator of x, y values for each point in a 2D rectangle defined by startx, endx, starty, endy values (ends not inclusive).
func GridCoords ¶ added in v1.4.0
GridCoords returns an iterator of Coord values for each point in a 2D rectangle defined by its top-left and bottom-right coordinates (inclusive).
func ParseIntList ¶ added in v1.9.0
func ParseLineIntList ¶
func ParseLineSplit ¶ added in v1.9.0
func ParseSplit ¶ added in v1.9.0
func Prod ¶ added in v1.8.0
func Prod[E mulable](s []E) E
Prod returns the product of all elements in the slice.
func ProdFunc ¶ added in v1.8.0
func ProdFunc[S any, E mulable](s []S, f func(e S) E) E
ProdFunc maps each element using f and returns the product of the results.
func ReadInputBytes ¶
func ReadInputBytes() [][]byte
func ReadInputInt ¶
func ReadInputInt() []int
func ReadInputIntList ¶
func ReadInputIntList() [][]int
func ReadInputLine ¶
func ReadInputLine() string
func ReadInputLineIntList ¶
func ReadInputLineIntList() []int
func ReadInputLineSplit ¶
func ReadInputSplit ¶
func SetAtCoord ¶ added in v1.4.0
SetAtCoord sets the value at coord of a 2D slice of elements
func ShowBytesCondensed ¶
func ShowBytesCondensed(area [][]byte)
func ShowIntsCondensed ¶
func ShowIntsCondensed(area [][]int)
func ShowIntsCsv ¶
func ShowIntsCsv(area [][]int)
func ShowResult ¶
func ShowResult(values ...any)
ShowResult prints each value in a numbered list format. The numbering continues across multiple calls.
func Sum ¶ added in v1.2.0
func Sum[E addable](s []E) E
Sum returns the sum of all elements in the slice.
func SumFunc ¶ added in v1.2.0
func SumFunc[S any, E addable](s []S, f func(e S) E) E
SumFunc maps each element using f and returns the sum of the results.
Types ¶
type Coord ¶
type Coord struct {
X, Y int
}
Coord represents a 2D coordinate point
func (Coord) AllNeighbours ¶ added in v1.1.0
AllNeighbours returns all the adjacent coordinates of the given coordinate
In contrast to simple Neighbours, it returns all adjacent coordinates
func (Coord) AllNeighbours8 ¶ added in v1.1.0
AllNeighbours8 returns all the adjacent and diagonal coordinates of the given coordinate
In contrast to simple Neighbours8, it returns all coordinates
func (Coord) Neighbours ¶ added in v1.1.0
Neighbours returns the adjacent coordinates of the given coordinate
If an adjacent coordinate is outside the block defined by width and height, those coordinates are not returned
func (Coord) Neighbours8 ¶ added in v1.1.0
Neighbours8 returns the adjacent and diagonal coordinates of the given coordinate
If a coordinate is outside the block defined by width and height, those coordinates are not returned