Documentation ¶
Overview ¶
Package aoc are quick & dirty utilities for helping Maisem solve Advent of Code problems. (forked from bradfitz/aoc)
Index ¶
- func AbsDiff[T Number](x, y T) T
- func AnyKey[K comparable, V any](m map[K]V) K
- func Digit(r rune) int
- func Digits(line string) []int
- func Extrapolate[T Number](x []T, forward bool) (y T)
- func FloodFill[T comparable](grid Grid[T], start Pt, empty, fill T) int
- func Fold[T any, R any](in []T, f func(R, T) R, defVal R) R
- func GCD(a, b int) int
- func InitMap[K comparable, V any](m *map[K]V)
- func Int(s string) int
- func Ints(s ...string) []int
- func LCM(integers ...int) int
- func MustDo(err error)
- func MustGet[T any](v T, err error) T
- func Or[T any](list ...T) T
- func Parallel[I, O any](in []I, f func(I) O) []O
- func ParallelMapFold[A, B, C any](in []A, f func(A) B, f2 func(C, B) C, defVal C) C
- func ParseBinary(in string) int64
- func PolygonArea(pts []Pt) int
- func PolygonBoundedPoints(pts []Pt) int
- func PolygonPermimeter(pts []Pt) int
- func Run(year int, src []byte, slvr any)
- func SolveQuad[T Number](a, b, c T) (float64, float64)
- func Sum[T Number](nums ...T) T
- func TrimPrefix(s, prefix string) string
- type Direction
- type Edge
- type Graph
- func (g *Graph[K]) AddEdge(a, b K, dist int)
- func (g *Graph[K]) AddNode(a K)
- func (g *Graph[K]) AllShortestPaths() map[Edge[K]]int
- func (g *Graph[K]) Clone() *Graph[K]
- func (g *Graph[K]) Collapse()
- func (g Graph[K]) LongestPath(start, end K) (rp int, ok bool)
- func (g *Graph[T]) MinCut() []Edge[T]
- func (g *Graph[K]) NumPaths(start, end K) int
- func (g *Graph[K]) NumPathsWithRestriction(start, end K, canVisit func(x K, alreadyVisited map[K]int) bool) int
- func (g *Graph[K]) ReachableNodes(a K) map[K]bool
- func (g *Graph[K]) RemoveEdge(a, b K)
- func (g *Graph[K]) RemoveNode(a K)
- type Grid
- func (g Grid[T]) At(p Pt) T
- func (g Grid[T]) AtOk(p Pt) (T, bool)
- func (g Grid[T]) EdgePaths() []Path
- func (g Grid[T]) Hash() deephash.Sum
- func (g Grid[T]) Move(p Path) (Path, bool)
- func (g Grid[T]) RotateCounterClockwise() Grid[T]
- func (g Grid[T]) RotateCounterClockwiseInto(out [][]T)
- func (g Grid[T]) Set(p Pt, v T)
- func (g Grid[T]) Size() Pt
- func (grid Grid[T]) ToGraph(start Pt, allowDiagonals bool, disallowed func(T) bool) Graph[Pt]
- func (g Grid[T]) Transpose() Grid[T]
- func (g Grid[T]) TransposeInto(out Grid[T])
- type Number
- type PQ
- type PQI
- type Path
- type Pt
- type Pt2
- type Puzzle
- func (p *Puzzle) Debug(v ...any)
- func (p *Puzzle) Debugf(format string, args ...any)
- func (p *Puzzle) Description() []byte
- func (p *Puzzle) ForLines(onLine func(line string))
- func (p *Puzzle) ForLinesY(onLine func(int, string))
- func (p *Puzzle) Input() []byte
- func (p *Puzzle) Sample() sample
- func (p *Puzzle) Scanner() *bufio.Scanner
- type Queue
- type Segment
- type Stack
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsDiff ¶
func AbsDiff[T Number](x, y T) T
AbsDiff returns the absolute difference between x and y.
func AnyKey ¶
func AnyKey[K comparable, V any](m map[K]V) K
AnyKey returns any key from the map. It panics if the map is empty.
func Extrapolate ¶
Extrapolate returns the next value in the sequence x. If forward is true, it extrapolates the next value, otherwise it extrapolates the previous value in the sequence.
func FloodFill ¶
func FloodFill[T comparable](grid Grid[T], start Pt, empty, fill T) int
FloodFill fills all empty cells reachable from start with fill.
func InitMap ¶
func InitMap[K comparable, V any](m *map[K]V)
InitMap initializes a map if it is nil.
func Parallel ¶
func Parallel[I, O any](in []I, f func(I) O) []O
Parallel runs f in parallel for each value in in.
func ParallelMapFold ¶
func ParallelMapFold[A, B, C any](in []A, f func(A) B, f2 func(C, B) C, defVal C) C
ParallelMapFold maps the input to a new slice, then folds the result. It is equivalent to Fold(Parallel(in, f), f2, defVal).
func PolygonArea ¶
PolygonArea returns the area of the polygon defined by the points. It assumes the points are in clockwise order, and uses the shoelace formula.
func PolygonBoundedPoints ¶
PolygonBoundedPoints returns the number of points with integer coordinates inside the polygon defined by the points.
func PolygonPermimeter ¶
PolygonPerimeter returns the perimeter of the polygon defined by the points.
func TrimPrefix ¶
TrimPrefix trims the prefix from s. It panics if the prefix is not found.
Types ¶
type Edge ¶
type Edge[T comparable] struct { A, B T }
type Graph ¶
type Graph[K comparable] struct { Nodes map[K]bool Edges map[K]map[K]int }
func (*Graph[K]) AllShortestPaths ¶
func (*Graph[K]) Collapse ¶
func (g *Graph[K]) Collapse()
Collapse collapses the graph by removing any nodes with only two edges and merging the two edges into one.
func (Graph[K]) LongestPath ¶
LongestPath returns the size of the longest path from start to end.
func (*Graph[T]) MinCut ¶
MinCut calculates the minimum cut of a graph using the Stoer–Wagner algorithm. It returns a list of edges that make up the cut.
func (*Graph[K]) NumPathsWithRestriction ¶
func (*Graph[K]) ReachableNodes ¶
func (*Graph[K]) RemoveEdge ¶
func (g *Graph[K]) RemoveEdge(a, b K)
func (*Graph[K]) RemoveNode ¶
func (g *Graph[K]) RemoveNode(a K)
type Grid ¶
type Grid[T any] [][]T
func (Grid[T]) RotateCounterClockwise ¶
func (Grid[T]) RotateCounterClockwiseInto ¶
func (g Grid[T]) RotateCounterClockwiseInto(out [][]T)
func (Grid[T]) ToGraph ¶
ToGraph converts the grid into a graph. If allowDiagonals is true, then diagonal neighbors are included. If disallowed is not nil, it is additionally called on each cell, and if it returns true, that cell is not included in the graph.
func (Grid[T]) TransposeInto ¶
type Number ¶
type Number interface { constraints.Float | constraints.Integer }
Number is a type that can be used in math functions.
type Pt2 ¶
type Pt2[T constraints.Signed] struct { X, Y T }
func (Pt2[T]) ForImmediateNeighbors ¶
func (Pt2[T]) ForNeighbors ¶
type Puzzle ¶
type Puzzle struct { SampleMode bool // contains filtered or unexported fields }