Documentation ¶
Overview ¶
Package utils contains some util functions and types for Advent Of Code.
Index ¶
- func Abs(number int) int
- func CopyIntSlice(original []int) []int
- func Dist(size int, value int) [][]int
- func GetFileAsString(filepath string) (string, error)
- func GetReaderAsString(r io.Reader) (string, error)
- func GroupByEmptyLines(fileContents string) ([][]string, error)
- func IntPermutations(arr []int) [][]int
- func LinesAsInts(fileContents string) ([]int, error)
- func MakeIntMatrix(rows int, columns int) [][]int
- func ManhattanDistance(p1 Point2D, p2 Point2D) int
- func Max(a, b int) int
- func Min(a, b int) int
- func MinMax(a, b int) (int, int)
- func MustAtoi(strNum string) int
- func StringDigits(str string) []int
- func StringRunes(str string) []rune
- func TrimmedLines(fileContents string) []string
- func TrimmedLinesNoEmpty(fileContents string) []string
- type ErrorTolerantWriter
- type IntSet
- type Point2D
- type Rectangle
- type StringSet
- type StringStack
- type Vector2D
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CopyIntSlice ¶
CopyIntSlice takes a slice of ints and returns a copy of it.
func GetFileAsString ¶
GetFileAsString reads a file on the given path and returns its contents as a string with whitespace trimmed.
func GetReaderAsString ¶
GetReaderAsString reads a file on the given path and returns its contents as a string with whitespace trimmed.
func GroupByEmptyLines ¶
GroupByEmptyLines reads the contents fo the string and returns the lines in the file, grouped by empty lines separating the,
func IntPermutations ¶
IntPermutations generates all the permutations of integers using Heap's algorithm
func LinesAsInts ¶
LinesAsInts reads the string as a list of numbers.
func MakeIntMatrix ¶
MakeIntMatrix makes a matrix with the specified dimensions. The matrix is given as slices of slices.
func ManhattanDistance ¶
ManhattanDistance computes the Manhattan distance between 2 points
func MustAtoi ¶
MustAtoi converts a string to a number, but panics if the conversion fails. This avoids error handling, but must be used when the calling code is sure the string represents a number.
func StringDigits ¶
StringDigits returns a slice of ints with the digits in a string. The argument must be a string only with runes that represent digits
func StringRunes ¶
StringRunes returns a slice of runes in a string
func TrimmedLines ¶
TrimmedLines takes a string with the contents of a file and divides into it'elems lines. Whitespace is trimmed from every line.
func TrimmedLinesNoEmpty ¶
TrimmedLinesNoEmpty takes a string with the contents of a file and divides into it'elems lines. Whitespace is trimmed from every line.
Types ¶
type ErrorTolerantWriter ¶
type ErrorTolerantWriter struct {
// contains filtered or unexported fields
}
ErrorTolerantWriter is an io.Writer that is a wrapper around a regular io.Writer that has its writes write to the underlying writer, until an error occurs, at which point, further writes will do nothing. To check if an error occurred in any of the writes and how many bytes were written up until the first error happened, call w.Error() and w.Bytes() respectively.
func NewErrorTolerantWriter ¶
func NewErrorTolerantWriter(w io.Writer) *ErrorTolerantWriter
NewErrorTolerantWriter returns a new ErrorTolerantWriter with the given writer as the underlying writer.
func (*ErrorTolerantWriter) Bytes ¶
func (w *ErrorTolerantWriter) Bytes() int
Bytes returns the number of bytes written to the underlying writer. If an error occurred in any of the writes, returns the bytes written until the first error happened.
func (*ErrorTolerantWriter) Error ¶
func (w *ErrorTolerantWriter) Error() error
Error returns nil if no error occurred in any of the writes, otherwise returns the first error that happened.
func (*ErrorTolerantWriter) Write ¶
func (w *ErrorTolerantWriter) Write(p []byte) (int, error)
Write writes to the underlying writer if none of the previous writes returned an error, does nothing otherwise. The returned error is always nil, to check if any error happened in any of the writes, call w.Error().
type IntSet ¶
IntSet represents a set of integers
type Point2D ¶
Point2D represents a point in 2 dimensions with integer coordinates
func (Point2D) ManhattanDistance ¶
ManhattanDistance computes the manhattan distance between this point and another
type Rectangle ¶
Rectangle represents a rectangle in a grid of integer coordinates
func (*Rectangle) AmplitudeX ¶
AmplitudeX returns how large is the rectangle in the X (horizontal) axis
func (*Rectangle) AmplitudeY ¶
AmplitudeY returns how large is the rectangle in the Y (vertical) axis
func (*Rectangle) BottomLeftCorner ¶
BottomLeftCorner returns the bottom left corner of the rectangle
func (*Rectangle) BottomRightCorner ¶
BottomRightCorner returns the bottom right corner of the rectangle
func (*Rectangle) TopLeftCorner ¶
TopLeftCorner returns the top bottom corner of the rectangle
func (*Rectangle) TopRightCorner ¶
TopRightCorner returns the top right corner of the rectangle
type StringSet ¶
StringSet represents a set of strings
func NewStringSet ¶
NewStringSet returns a newly created string set
func StringSetIntersection ¶
type StringStack ¶
type StringStack struct {
// contains filtered or unexported fields
}
func NewStringStack ¶
func NewStringStack() *StringStack
func (*StringStack) Elems ¶
func (s *StringStack) Elems() int
func (*StringStack) IsEmpty ¶
func (s *StringStack) IsEmpty() bool
func (*StringStack) Pop ¶
func (s *StringStack) Pop() string
func (*StringStack) Push ¶
func (s *StringStack) Push(elem string)
type Vector2D ¶
Vector2D is a vector in 2 dimensions