lib

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2022 License: MIT Imports: 8 Imported by: 41

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetInput

func GetInput(filename string) ([]string, error)

GetInput will return a slice of strings, one entry per line, in-order.

func GetInputAsSections

func GetInputAsSections(filename string) ([][]string, error)

GetInputAsSections returns back the input as a slice of string slices, where each top-level slice represents a section of the input. Useful for puzzle inputs with multiple sections e.g 2020 day 19.

func Volume

func Volume(p Point3D) int

Volume calculates the volume of a cube with a corner at p and a corner at the origin (0, 0, 0).

Types

type Deque

type Deque interface {
	PushTop(data int)
	PeekTop() (int, bool)
	PopTop() int
	PushBottom(data int)
	PeekBottom() (int, bool)
	PopBottom() int
	IsEmpty() bool
	Count() int
	TakeTop(int) Deque
	Visit(NodeVisitor)
	String() string
}

func NewDeque

func NewDeque(input []int) Deque

type IntervalTreeNode

type IntervalTreeNode struct {
	CenterPoint          int
	CenterIntervalsByMin []*Range
	CenterIntervalsByMax []*Range
	Left                 *IntervalTreeNode
	Right                *IntervalTreeNode
}

IntervalTreeNode stores a set of intervals in a binary tree for simplified retrieval.

func NewIntervalTree

func NewIntervalTree(input []*Range) (*IntervalTreeNode, error)

NewIntervalTree returns the root of an interval tree containing all specified intervals, provided all intervals are valid.

func (*IntervalTreeNode) Find

func (i *IntervalTreeNode) Find(query int) []*Range

Find returns a slice of intervals containing the given point, inclusive of bounds.

func (*IntervalTreeNode) FindRange

func (i *IntervalTreeNode) FindRange(query *Range) []*Range

type LinkedList

type LinkedList struct {
	Head *LinkedListNode
	Tail *LinkedListNode
}

func (*LinkedList) String

func (l *LinkedList) String() string

type LinkedListBuilder

type LinkedListBuilder struct {
	// contains filtered or unexported fields
}

func (*LinkedListBuilder) AddItem

func (b *LinkedListBuilder) AddItem(data int) *LinkedListNode

func (*LinkedListBuilder) GetList

func (b *LinkedListBuilder) GetList() *LinkedList

type LinkedListNode

type LinkedListNode struct {
	Data int
	Next *LinkedListNode
}

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

func NewMatrix

func NewMatrix(s []string) *Matrix

func NewMatrixWithoutFrame

func NewMatrixWithoutFrame(s []string) *Matrix

func (*Matrix) FlipHorizontal

func (m *Matrix) FlipHorizontal()

func (*Matrix) FlipVertical

func (m *Matrix) FlipVertical()

func (*Matrix) Rotate

func (m *Matrix) Rotate()

func (*Matrix) String

func (m *Matrix) String() string

type NodeVisitor

type NodeVisitor func(int)

type Point3D

type Point3D struct {
	X, Y, Z int
}

Point3D represents an arbitrary point in 3D space

func (Point3D) Add

func (p Point3D) Add(other Point3D) Point3D

Add will perform vector addition and return a new Point3D

func (Point3D) Neighbors

func (p Point3D) Neighbors() []Point3D

Neighbors returns the 26 coordinates surrounding the given point.

func (Point3D) Sub

func (p Point3D) Sub(other Point3D) Point3D

Sub will perform vector subtraction and return a new Point3D with other being the right-hand operand.

type Point4D

type Point4D struct {
	X, Y, Z, W int
}

Point4D represents an arbitrary point in 3D space

func (Point4D) Add

func (p Point4D) Add(other Point4D) Point4D

Add will perform vector addition and return a new Point4D

func (Point4D) Neighbors

func (p Point4D) Neighbors() []Point4D

Neighbors returns the 80 coordinates surrounding the given point.

func (Point4D) Sub

func (p Point4D) Sub(other Point4D) Point4D

Sub will perform vector subtraction and return a new Point4D with other being the right-hand operand.

type Range

type Range struct {
	Min      int
	Max      int
	Metadata interface{}
}

Range encapsulates the min and max values for an interval and allows the user to specify some sort of metadata.

func (*Range) Contains

func (r *Range) Contains(query int) bool

Contains will establish that the given query falls in the bounds of the Range, inclusive of min/max.

func (*Range) Overlaps

func (r *Range) Overlaps(o *Range) bool

Overlaps will return true when the range overlaps with the specified range, inclusive of min/max.

func (*Range) Valid

func (r *Range) Valid() bool

Valid will return true when the range Min val is strictly less than the range Max val.

type StringStack

type StringStack []string

StringStack is a stack that...well, it holds strings.

func (*StringStack) IsEmpty

func (s *StringStack) IsEmpty() bool

IsEmpty returns true when the stack has no items, false otherwise.

func (*StringStack) Peek

func (s *StringStack) Peek() (string, bool)

Peek will let us see the most-recently added item without removing it from the stack.

func (*StringStack) Pop

func (s *StringStack) Pop() (string, bool)

Pop removes the most-recently added item from the stack and returns it. If the stack is empty, we'll return an empty string and a false boolean.

func (*StringStack) Push

func (s *StringStack) Push(input string)

Push adds a new item to the top of the Stack

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL