Documentation ¶
Overview ¶
Package aocutils is a collection of commonly used functions that might be helpful for Advent of Code solving. User puzzle input can be obtained without importing this sub-package if you wish to handle all of that yourself.
Index ¶
- func AverageListOfNums[n Number](elements []n) n
- func Distance2D[n Number](x1, y1, x2, y2 n) float64
- func Distance3D[n Number](x1, y1, z1, x2, y2, z2 n) float64
- func ExtractIntsFromString(input string) []int
- func FindDuplicates[v Value](elements []v) []v
- func FindSubstringsOfLength(s string, length int) []string
- func FlattenList[v Value](nested [][]v) []v
- func ManhattanDistance2D(x1, y1, x2, y2 int) int
- func ManhattanDistance3D(x1, y1, z1, x2, y2, z2 int) int
- func NthElements[v Value](elements []v, n int) []v
- func NumOccurrences[v Value](elements []v, target v) int
- func RemoveDuplicates[v Value](elements []v) []v
- func ReverseSlice[v Value](elements []v) []v
- func TransposeMatrix[v Value](matrix [][]v) [][]v
- type Number
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AverageListOfNums ¶
func AverageListOfNums[n Number](elements []n) n
AverageListOfNums takes a list of Number elements and returns the average of all of them.
func Distance2D ¶
Distance2D calculates the Euclidean distance between two points in 2D space. Returns the distance as a float64.
func Distance3D ¶
Distance3D calculates the Euclidean distance between two points in 3D space. Returns the distance as a float64.
func ExtractIntsFromString ¶
ExtractIntsFromString will find all groups of consecutive digits in a string. Returns a slice of all integers extracted from the input string.
func FindDuplicates ¶
func FindDuplicates[v Value](elements []v) []v
FindDuplicates will find any elements that appear more than once in the slice. Returns a slice containing all duplicates that appear in the input slice.
func FindSubstringsOfLength ¶
FindSubstringsOfLength takes a string and a desired length, and returns all unique substrings of that length. Returns a slice of substrings.
func FlattenList ¶
func FlattenList[v Value](nested [][]v) []v
FlattenList takes a slice matrix of values and will turn it into a 1D slice. Returns a 1D slice, constructed by appending each row of the matrix to one another in order.
func ManhattanDistance2D ¶
ManhattanDistance2D calculates the Manhattan distance between two points in 2D space. Returns the distance as an int.
func ManhattanDistance3D ¶
ManhattanDistance3D calculates the Manhattan distance between two points in 3D space. Returns the distance as an int.
func NthElements ¶
NthElements takes a slice of elements and an interval. Returns a slice of the elements occuring every `n` spots of the original array.
func NumOccurrences ¶
NumOccurrences counts the number of times a specific value occurs in a slice. Returns the count of occurrences of the target value in the input slice.
func RemoveDuplicates ¶
func RemoveDuplicates[v Value](elements []v) []v
RemoveDuplicates removes duplicate elements from a slice. Returns a new slice with only unique elements, preserving the order of their first occurrence.
func ReverseSlice ¶
func ReverseSlice[v Value](elements []v) []v
ReverseSlice reverses the order of elements in a slice. Returns a new slice with the elements in reverse order.
func TransposeMatrix ¶
func TransposeMatrix[v Value](matrix [][]v) [][]v
TransposeMatrix takes a 2D slice (matrix) and transposes it (swaps rows and columns). Returns the transposed matrix as a new 2D slice.