Documentation ¶
Overview ¶
Package aoc provides some Advent of Code utilities.
Index ¶
- func Abs(a int) int
- func FilterSliceIndices[T any](in []T, indices []int) []T
- func FindStringIndices(s string, search string) []int
- func GreatestCommonDivisor(a, b int) int
- 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 MapKeysToSlice[K comparable, V any](m map[K]V) []K
- func MapValuesToSlice[K comparable, V any](m map[K]V) []V
- func Mod(d, m int) int
- 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 SliceToMap[K comparable, V any](s []K, f func(K) V) map[K]V
- func SliceToSet[T comparable](s []T) map[T]bool
- 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
- type CapturingGroup
- type DAG
- type DAGNode
- type Delimiter
- type DelimiterOption
- type Direction
- type Location
- type Node
- type Position
- type PriorityQueue
- type Submatch
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterSliceIndices ¶ added in v1.10.3
func FindStringIndices ¶ added in v1.11.0
FindStringIndices returns all the indices from a given string into a string.
func GreatestCommonDivisor ¶
GreatestCommonDivisor returns the greatest common divisor of two numbers.
func IsRuneDecimal ¶
IsRuneDecimal checks whether a rune is a decimal number.
func IsSliceMonotonicallyDecreasing ¶ added in v1.10.1
func IsSliceMonotonicallyDecreasing[T constraints.Ordered](in []T) bool
func IsSliceMonotonicallyIncreasing ¶ added in v1.10.1
func IsSliceMonotonicallyIncreasing[T constraints.Ordered](in []T) bool
func IsSliceSorted ¶ added in v1.10.3
func IsSliceSorted[T constraints.Ordered](in []T, comp func(a T, b T) bool) bool
func IsSliceStrictlyDecreasing ¶ added in v1.10.1
func IsSliceStrictlyDecreasing[T constraints.Ordered](in []T) bool
func IsSliceStrictlyIncreasing ¶ added in v1.10.1
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 MapKeysToSlice ¶ added in v1.9.0
func MapKeysToSlice[K comparable, V any](m map[K]V) []K
MapKeysToSlice converts the maps keys to a slice.
func MapValuesToSlice ¶ added in v1.9.0
func MapValuesToSlice[K comparable, V any](m map[K]V) []V
MapValuesToSlice converts the map values to a slice.
func ReaderToInts ¶
ReaderToInts converts optimistically an io.Reader into a slice of strings.
func ReaderToString ¶
ReaderToString converts an io.Reader into a string.
func ReaderToStrings ¶
ReaderToStrings converts an io.Reader into a slice of strings.
func RegexpFindAll ¶ added in v1.11.0
RegexpFindAll finds all occurrences of a regexp.
func SliceCount ¶ added in v1.11.0
func SliceCount[T comparable](in []T) map[T]int
func SliceToMap ¶ added in v1.9.0
func SliceToMap[K comparable, V any](s []K, f func(K) V) map[K]V
SliceToMap converts a slice into a map.
func SliceToSet ¶ added in v1.10.3
func SliceToSet[T comparable](s []T) map[T]bool
SliceToSet converts a slice into a set.
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 is an optimistic conversion from a string to an int.
func StringsToInts ¶
StringsToInts is an optimistic conversion from a slice of strings to a slice of ints.
func TopologicalSort ¶ added in v1.9.0
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 ¶ added in v1.6.1
type Board[T any] struct { Positions map[Position]T MinRows int MinCols int MaxRows int MaxCols int }
func NewBoardFromReader ¶ added in v1.11.2
NewBoardFromReader creates a board from an input reader.
func ParseBoard ¶ added in v1.4.0
ParseBoard parses a board and maps it to a map of Position.
type CapturingGroup ¶ added in v1.11.0
func RegexpFindIndices ¶ added in v1.11.0
func RegexpFindIndices(s string, re *regexp.Regexp) []CapturingGroup
RegexpFindIndices finds all the indices of a regexp.
type DAG ¶ added in v1.9.0
type DAG[K comparable, V any] struct { // contains filtered or unexported fields }
DAG is the representation of a directed acyclic graph.
func NewDAG ¶ added in v1.9.0
func NewDAG[K comparable, V any]() DAG[K, V]
NewDAG returns a new DAG.
func (DAG[K, V]) AddSimpleEdge ¶ added in v1.9.0
func (g DAG[K, V]) AddSimpleEdge(from, to K)
AddSimpleEdge adds a simple edge, without the DAGNode.
func (DAG[K, V]) TopologicalSort ¶ added in v1.9.0
func (g DAG[K, V]) TopologicalSort() []K
TopologicalSort applies the topological sort algorithm on a DAG.
type DAGNode ¶ added in v1.9.0
type DAGNode[K comparable, V any] struct { Id K Data V }
DAGNode is a DAG node.
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 Direction ¶
type Direction int
Direction enum
type Location ¶ added in v1.2.0
Location represents a given position and direction.
func NewLocation ¶ added in v1.3.0
NewLocation creates a new location.
type Node ¶ added in v1.7.0
Node is a linked list node.
func (*Node[T]) InsertAfter ¶ added in v1.7.0
func (n *Node[T]) InsertAfter(data T)
InsertAfter insers a node after the current one.
func (*Node[T]) InsertHead ¶ added in v1.7.0
InsertHead inserts a node to the head and return the head.
func (*Node[T]) InsertTail ¶ added in v1.7.0
InsertTail inserts a node to the tail and return the tail.
type Position ¶
Position represents a given position (row/col)
func NewPosition ¶ added in v1.3.0
NewPosition creates a new position.
func (Position) ManhattanZero ¶
ManhattanZero returns the manhattan distance from the zero position.
type PriorityQueue ¶ added in v1.5.0
type PriorityQueue[T comparable] struct { // contains filtered or unexported fields }
PriorityQueue is a priority queue implementation.
func NewPriorityQueue ¶ added in v1.5.0
func NewPriorityQueue[T comparable](comparator func(a, b T) bool) PriorityQueue[T]
NewPriorityQueue creates a new PriorityQueue using a comparator.
func (*PriorityQueue[T]) IsEmpty ¶ added in v1.5.0
func (pq *PriorityQueue[T]) IsEmpty() bool
IsEmpty checks if the priority queue is empty.
func (*PriorityQueue[T]) Len ¶ added in v1.5.1
func (pq *PriorityQueue[T]) Len() int
Len returns the number of elements in the priority queue.
func (*PriorityQueue[T]) Peek ¶ added in v1.5.0
func (pq *PriorityQueue[T]) Peek() T
Peek returns the top element of the priority queue without removing it.
func (*PriorityQueue[T]) Pop ¶ added in v1.5.0
func (pq *PriorityQueue[T]) Pop() T
Pop removes and returns the top element from the priority queue.
func (*PriorityQueue[T]) Push ¶ added in v1.5.0
func (pq *PriorityQueue[T]) Push(item T)
Push pushes a new item.
type Submatch ¶ added in v1.11.0
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 }