Documentation
¶
Overview ¶
Package aoc provides some utilities for completing and Advent of Code.
Index ¶
- func Abs(a int) int
- func DeleteSliceIndex[T any](in []T, index int, deepCopy bool) []T
- func DeleteSliceIndices[T any](in []T, indices []int, deepCopy bool) []T
- func GreatestCommonDivisor(a, b int) int
- func InnerMapGet[K1 comparable, K2 comparable, X any](m map[K1]map[K2]X, k K1, cap ...int) map[K2]X
- func IntToRune(i int) rune
- func IsRuneDecimal(r rune) bool
- func IsSliceMonotonicallyDecreasing[T constraints.Ordered](in []T) bool
- func IsSliceMonotonicallyIncreasing[T constraints.Ordered](in []T) bool
- func IsSliceSorted[T constraints.Ordered](in []T, comp func(a T, b T) bool) bool
- func IsSliceStrictlyDecreasing[T constraints.Ordered](in []T) bool
- func IsSliceStrictlyIncreasing[T constraints.Ordered](in []T) bool
- func LeastCommonMultiple(numbers []int) int
- func ManhattanDistance(row, col int) int
- func MapCopy[K comparable, V any](m map[K]V) map[K]V
- func MapKeysToSlice[K comparable, V any](m map[K]V) []K
- func MapPositionsToString[V any](positions map[Position]V) string
- func MapSwitch[K, V comparable](m map[K]V) map[V]K
- func MapValuesToSlice[K comparable, V any](m map[K]V) []V
- func Mod(d, m int) int
- func Over[T any](ts ...T) iter.Seq[T]
- func ReaderToInts(input io.Reader) []int
- func ReaderToString(input io.Reader) string
- func ReaderToStrings(input io.Reader) []string
- func RegexpFindAll(s string, re *regexp.Regexp) []string
- func RuneToInt(r rune) int
- func SliceCopy[T any](in []T) []T
- func SliceCount[T comparable](in []T) map[T]int
- func SlicePositionsToString(positions []Position) string
- func SliceToMap[K comparable, V any](s []K, f func(K) V) map[K]V
- func SliceToSet[T comparable](s []T) map[T]bool
- func StringFindIndices(s string, search string) []int
- func StringGroups(lines []string) [][]string
- func StringToInt(s string) int
- func StringsToInts(s []string) []int
- func Substring(s string, del string) string
- func TopologicalSort[K comparable](vertices []K, edgesFunc func(K) []K) []K
- func TryStringToInt(s string) (int, bool)
- type Board
- func NewBoard[T any](positions map[Position]T) Board[T]
- func NewBoardFromElements[T any](elements []BoardElement[T], rows, cols int) Board[T]
- func NewBoardFromLength[T any](fromRow, toRow, fromCol, toCol int, zero T) Board[T]
- func NewBoardFromReader[T any](input io.Reader, f func(row, col int, r rune) T) Board[T]
- func NewBoardWithLength[T any](positions map[Position]T, rows, cols int) Board[T]
- func ParseBoard[T any](lines []string, fn func(r rune, pos Position) T) Board[T]
- type BoardElement
- type CapturingGroup
- type DAG
- type DAGNode
- type Delimiter
- type DelimiterOption
- type Direction
- type Heap
- type Location
- type Node
- type Pair
- type Position
- type Submatch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteSliceIndex ¶ added in v1.0.1
DeleteSliceIndex deletes a given index.
func DeleteSliceIndices ¶ added in v1.0.1
DeleteSliceIndices deletes a list of indices.
func GreatestCommonDivisor ¶
GreatestCommonDivisor returns the greatest common divisor of two numbers.
func InnerMapGet ¶
func InnerMapGet[K1 comparable, K2 comparable, X any](m map[K1]map[K2]X, k K1, cap ...int) map[K2]X
InnerMapGet performs a get or init in an inner map.
func IsRuneDecimal ¶
IsRuneDecimal checks whether a rune is a decimal number.
func IsSliceMonotonicallyDecreasing ¶
func IsSliceMonotonicallyDecreasing[T constraints.Ordered](in []T) bool
func IsSliceMonotonicallyIncreasing ¶
func IsSliceMonotonicallyIncreasing[T constraints.Ordered](in []T) bool
func IsSliceSorted ¶
func IsSliceSorted[T constraints.Ordered](in []T, comp func(a T, b T) bool) bool
func IsSliceStrictlyDecreasing ¶
func IsSliceStrictlyDecreasing[T constraints.Ordered](in []T) bool
func IsSliceStrictlyIncreasing ¶
func IsSliceStrictlyIncreasing[T constraints.Ordered](in []T) bool
func LeastCommonMultiple ¶
LeastCommonMultiple returns the least common multiple from a list of numbers.
func ManhattanDistance ¶
ManhattanDistance returns the manhattan distance.
func MapCopy ¶ added in v1.0.3
func MapCopy[K comparable, V any](m map[K]V) map[K]V
func MapKeysToSlice ¶
func MapKeysToSlice[K comparable, V any](m map[K]V) []K
MapKeysToSlice converts the maps keys to a slice.
func MapPositionsToString ¶ added in v1.0.4
func MapSwitch ¶ added in v1.0.12
func MapSwitch[K, V comparable](m map[K]V) map[V]K
func MapValuesToSlice ¶
func MapValuesToSlice[K comparable, V any](m map[K]V) []V
MapValuesToSlice converts the map values to a slice.
func ReaderToInts ¶
ReaderToInts converts an io.Reader into a slice of strings. It panics in case of a parsing error.
func ReaderToString ¶
ReaderToString converts an io.Reader into a string.
func ReaderToStrings ¶
ReaderToStrings converts an io.Reader into a slice of strings.
func RegexpFindAll ¶
RegexpFindAll finds all occurrences of a regexp.
func SliceCount ¶
func SliceCount[T comparable](in []T) map[T]int
func SlicePositionsToString ¶ added in v1.0.4
func SliceToMap ¶
func SliceToMap[K comparable, V any](s []K, f func(K) V) map[K]V
SliceToMap converts a slice into a map.
func SliceToSet ¶
func SliceToSet[T comparable](s []T) map[T]bool
SliceToSet converts a slice into a set (a map where all the keys are the elements from the slice and the values are true).
func StringFindIndices ¶
StringFindIndices returns all the indices from a given string into a string.
func StringGroups ¶
StringGroups returns groups of lines inputs that are not separated by empty lines.
For example:
0, 1, 2
foo bar
Returns {"0, 1, 2"} and {"foo", "bar"}
func StringToInt ¶
StringToInt converts a string into an int. It panics in case of a parsing error.
func StringsToInts ¶
StringsToInts converts a slice of strings to a slice of ints. It panics in case of a parsing error.
func TopologicalSort ¶
func TopologicalSort[K comparable](vertices []K, edgesFunc func(K) []K) []K
TopologicalSort applies the topological sort algorithm based on vertices and a way to compute the edges.
func TryStringToInt ¶
TryStringToInt tries to convert a string into an int.
Types ¶
type Board ¶
type Board[T any] struct { Positions map[Position]T MinRows int MinCols int MaxRows int MaxCols int }
func NewBoardFromElements ¶ added in v1.0.7
func NewBoardFromElements[T any](elements []BoardElement[T], rows, cols int) Board[T]
func NewBoardFromLength ¶ added in v1.0.5
func NewBoardFromReader ¶
NewBoardFromReader creates a board from an input reader.
func NewBoardWithLength ¶ added in v1.0.6
func ParseBoard ¶
ParseBoard parses a board and maps it to a map of Position.
type BoardElement ¶ added in v1.0.7
type CapturingGroup ¶
func RegexpFindIndices ¶
func RegexpFindIndices(s string, re *regexp.Regexp) []CapturingGroup
RegexpFindIndices finds all the indices of a regexp.
type DAG ¶
type DAG[K comparable, V any] struct { // contains filtered or unexported fields }
DAG is the representation of a directed acyclic graph.
func (DAG[K, V]) AddSimpleEdge ¶
func (g DAG[K, V]) AddSimpleEdge(from, to K)
AddSimpleEdge adds a simple edge, without the DAGNode.
func (DAG[K, V]) TopologicalSort ¶
func (g DAG[K, V]) TopologicalSort() []K
TopologicalSort applies the topological sort algorithm on a DAG.
type Delimiter ¶
type Delimiter struct {
// contains filtered or unexported fields
}
Delimiter implementation.
func NewDelimiter ¶
func NewDelimiter(s, del string, opts ...DelimiterOption) Delimiter
NewDelimiter creates a new input delimiter logic.
func (Delimiter) GetStrings ¶
GetStrings returns all the strings found.
type DelimiterOption ¶
type DelimiterOption func(options *delimiterOptions)
DelimiterOption holds the Delimiter options.
func WithTrimSpace ¶
func WithTrimSpace() DelimiterOption
WithTrimSpace applies strings.trimSpace on each string.
type Heap ¶ added in v1.0.1
type Heap[T any] struct { // contains filtered or unexported fields }
Heap is a priority queue implementation.
func (*Heap[T]) Peek ¶ added in v1.0.1
func (pq *Heap[T]) Peek() T
Peek returns the top element of the priority queue without removing it.
type Location ¶
Location represents a given position and direction.
func NewLocation ¶
NewLocation creates a new location.
type Node ¶
Node is a linked list node.
func (*Node[T]) InsertAfter ¶
func (n *Node[T]) InsertAfter(data T)
InsertAfter insers a node after the current one.
func (*Node[T]) InsertHead ¶
InsertHead inserts a node to the head and return the head.
func (*Node[T]) InsertTail ¶
InsertTail inserts a node to the tail and return the tail.
type Position ¶
Position represents a given position (row/col)
func (Position) ManhattanZero ¶
ManhattanZero returns the manhattan distance from the zero position.
type Submatch ¶
type Submatch struct { Start int End int // CapturingGroups is a list of optional capturing groups. // For example, `mul\((\d{1,3}),(\d{1,3})\)` contains 2 capturing groups. CapturingGroups []CapturingGroup }