aoc

package
v0.0.0-...-abdf023 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: MIT Imports: 12 Imported by: 0

README

advent/lib-go

Some utilities to help with Advent of Code puzzles

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EightNeighbourOffsets = []Point{
	Point{X: -1, Y: -1}, Point{X: 0, Y: -1}, Point{X: 1, Y: -1},
	Point{X: -1, Y: 0}, Point{X: 1, Y: 0},
	Point{X: -1, Y: 1}, Point{X: 0, Y: 1}, Point{X: 1, Y: 1},
}
View Source
var FourNeighbourOffsets = []Point{
	Point{X: 0, Y: -1},
	Point{X: -1, Y: 0}, Point{X: 1, Y: 0},
	Point{X: 0, Y: 1},
}

Functions

func Abs

func Abs[T AoCSigned](x T) T

func Abs64

func Abs64(a int64) int64

func AlphaNum

func AlphaNum(ch byte) int

func BinToInt

func BinToInt(s string) int

func Blue

func Blue(s string) string

func Bold

func Bold(s string) string

func CRT

func CRT(a, n []*big.Int) (*big.Int, error)

func ChineseRemainderTheorem

func ChineseRemainderTheorem[T AoCInt](an [][2]T) *T

func ChompInt

func ChompInt[T AoCSigned](in []byte, i int) (int, T)

func ChompOneOrTwoCharUInt

func ChompOneOrTwoCharUInt[T AoCInt](in []byte, i int) (int, T)

func ChompToNextLine

func ChompToNextLine(in []byte, i int) int

func ChompUInt

func ChompUInt[T AoCInt](in []byte, i int) (j int, n T)

func ClearScreen

func ClearScreen() string

func CursorTo

func CursorTo(x int, y int) string

func Cyan

func Cyan(s string) string

func DEBUG

func DEBUG() bool

func EGCD

func EGCD[T AoCInt](a, b T, x, y *T) T

func FP2UKeyMax

func FP2UKeyMax(bits int) int

func FP3UKeyMax

func FP3UKeyMax(bits int, zbits int) int

func FastBytes

func FastBytes(l []byte) []byte

func FastInt64s

func FastInt64s(l []byte, expected int) []int64

func FastInts

func FastInts(l []byte, expected int) []int

func FastSignedInts

func FastSignedInts(l []byte, expected int) []int

func GCD

func GCD(a, b int64) int64

func Green

func Green(s string) string

func InputBytes

func InputBytes(embedded []byte) []byte

func InputChunks

func InputChunks(embedded []byte) []string

func InputFile

func InputFile() string

func InputInts

func InputInts(embedded []byte) []int

func InputLines

func InputLines(embedded []byte) []string

func InputString

func InputString(embedded []byte) string

func IntListContains

func IntListContains(l []int, e int) bool

func IntToBin

func IntToBin(n int) string

func Ints

func Ints(l string) []int

func LCM

func LCM(a, b int64, integers ...int64) int64

func Magenta

func Magenta(s string) string

func Max

func Max[T AoCInt](a ...T) T

func MaxInt

func MaxInt(a ...int) int

func MaxInt64

func MaxInt64(a ...int64) int64

func MedianOfMedians

func MedianOfMedians(inp []int, n int) int

func Min

func Min[T AoCInt](a ...T) T

func MinInt

func MinInt(a ...int) int

func MinInt64

func MinInt64(a ...int64) int64

func Mod

func Mod[T AoCSigned](n, m T) T

func ModExp

func ModExp(b, e, m uint) uint

func MustParseInt

func MustParseInt(s string) int

func MustParseInt64

func MustParseInt64(s string) int64

func MustParseUint

func MustParseUint(s string) uint

func MustParseUint64

func MustParseUint64(s string) uint64

func NeverToBigMod

func NeverToBigMod[T AoCSigned](n, m T) T

func NumAlpha

func NumAlpha(c int) byte

func NumString

func NumString(n int) string

func NumberString

func NumberString(s string) string

func NumberStrings

func NumberStrings(s string) []string

func Permutations

func Permutations(min, max int) [][]int

func Product

func Product[T AoCInt](ints ...T) T

func Product64

func Product64(ints ...int64) int64

func ReadChunks

func ReadChunks(file string) []string

func ReadFileBytes

func ReadFileBytes(file string) []byte

func ReadFileChunks

func ReadFileChunks(file string) []string

func ReadFileIntLines

func ReadFileIntLines(file string) [][]int

func ReadFileInts

func ReadFileInts(file string) []int

func ReadFileLines

func ReadFileLines(file string) []string

func ReadInputBytes

func ReadInputBytes() []byte

func ReadInputChunks

func ReadInputChunks() []string

func ReadInputIntLines

func ReadInputIntLines() [][]int

func ReadInputInts

func ReadInputInts() []int

func ReadInputLines

func ReadInputLines() []string

func ReadInt64s

func ReadInt64s(lines []string) ([]int64, error)

func ReadInts

func ReadInts(in []string) []int

func ReadIntsFromFile

func ReadIntsFromFile(file string) []int

ReadIntsFromFile slurps input from a file into a list of integers

func ReadLines

func ReadLines(file string) []string

ReadLines slurps input from a file into a list of lines (strings)

func Red

func Red(s string) string

func ReverseIntList

func ReverseIntList(lines []int) []int

func ReverseString

func ReverseString(s string) (r string)

func ReverseStringList

func ReverseStringList(lines []string) []string

func RotateStrings

func RotateStrings(lines []string) []string

func ScanInt

func ScanInt(in []byte, i int) (int, int)

func ScanUint

func ScanUint(in []byte, i int) (int, int)

func Screen

func Screen() (int, int)

func SimpleMedianN

func SimpleMedianN(inp []int, n int) int

func SimpleReadInt64s

func SimpleReadInt64s(l string) []int64

func SimpleReadInts

func SimpleReadInts(l string) []int

func StringListContains

func StringListContains(l []string, e string) bool

func Sum

func Sum[T AoCInt](ints ...T) T

func Sum64

func Sum64(ints ...int64) int64

func VISUAL

func VISUAL() bool

func Variations

func Variations(k, n int) [][]int

func VisitInts

func VisitInts[T AoCSigned](in []byte, until byte, i *int, fn func(n T))

func VisitSplit

func VisitSplit(in []byte, sep, until byte, i *int, fn func(s []byte))

func VisitUints

func VisitUints[T AoCInt](in []byte, until byte, i *int, fn func(n T))

func VisitWords

func VisitWords(in []byte, until byte, i *int, fn func(w []byte, term byte))

func XSloppyReadInts

func XSloppyReadInts(lines []string) []int

func Yellow

func Yellow(s string) string

Types

type AlphaNumSet

type AlphaNumSet uint64

func AlphaNumBit

func AlphaNumBit(ch byte) AlphaNumSet

func NewAlphaNumSet

func NewAlphaNumSet() AlphaNumSet

func (AlphaNumSet) Add

func (s AlphaNumSet) Add(ch byte) AlphaNumSet

func (AlphaNumSet) Contains

func (s AlphaNumSet) Contains(ch byte) bool

func (AlphaNumSet) Size

func (s AlphaNumSet) Size() int

func (AlphaNumSet) String

func (s AlphaNumSet) String() string

type AoCInt

type AoCInt interface{ AoCUnsigned | AoCSigned }

type AoCSigned

type AoCSigned interface {
	~byte | int | ~int8 | ~int16 | ~int32 | ~int64
}

type AoCUnsigned

type AoCUnsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
}

type BoundingBox

type BoundingBox struct {
	Min Point
	Max Point
}

BoundingBox is a 2D bounding box representing by min and max points

func NewBoundingBox

func NewBoundingBox() *BoundingBox

func (*BoundingBox) Add

func (bb *BoundingBox) Add(p Point)

func (*BoundingBox) Contains

func (bb *BoundingBox) Contains(p Point) bool

func (*BoundingBox) String

func (bb *BoundingBox) String() string

type ByteCounter

type ByteCounter interface {
	Inc(byte)
	Add(byte, int)
	Top(int) []byte
	Bottom(int) []byte
	Count(byte) int
}

func NewMapByteCounter

func NewMapByteCounter(n int) ByteCounter

func NewSliceByteCounter

func NewSliceByteCounter(n int) ByteCounter

type ByteMap

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

func NewByteMap

func NewByteMap(in []byte) (i *ByteMap)

func (*ByteMap) Add

func (m *ByteMap) Add(i int, v byte)

func (*ByteMap) Contains

func (m *ByteMap) Contains(i int) bool

func (*ByteMap) Get

func (m *ByteMap) Get(i int) byte

func (*ByteMap) GetXY

func (m *ByteMap) GetXY(x, y int) byte

func (*ByteMap) Height

func (m *ByteMap) Height() int

func (*ByteMap) IndexToString

func (m *ByteMap) IndexToString(i int) string

func (*ByteMap) IndexToXY

func (m *ByteMap) IndexToXY(i int) (int, int)

func (*ByteMap) NeighbourValues

func (m *ByteMap) NeighbourValues(i int) []byte

func (*ByteMap) Neighbours

func (m *ByteMap) Neighbours(i int) []int

func (*ByteMap) Neighbours8

func (m *ByteMap) Neighbours8(i int) []int

func (*ByteMap) Set

func (m *ByteMap) Set(i int, v byte)

func (*ByteMap) SetXY

func (m *ByteMap) SetXY(x, y int, v byte)

func (*ByteMap) Size

func (m *ByteMap) Size() int

func (*ByteMap) String

func (m *ByteMap) String() string

func (*ByteMap) Visit

func (m *ByteMap) Visit(fn func(i int, v byte) (byte, bool))

func (*ByteMap) VisitNeighbours

func (m *ByteMap) VisitNeighbours(i int, fn func(int, byte))

func (*ByteMap) VisitNeighboursXY

func (m *ByteMap) VisitNeighboursXY(x, y int, fn func(int, int, byte))

func (*ByteMap) VisitXY

func (m *ByteMap) VisitXY(fn func(x, y int, v byte) (byte, bool))

func (*ByteMap) VisitXYI

func (m *ByteMap) VisitXYI(fn func(x, y, i int, v byte) (byte, bool))

func (*ByteMap) Width

func (m *ByteMap) Width() int

func (*ByteMap) XYToIndex

func (m *ByteMap) XYToIndex(x, y int) int

type CharCount

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

type Circle

type Circle struct {
	Num int
	Cw  *Circle
	Ccw *Circle
}

func NewCircle

func NewCircle(i int) *Circle

func (*Circle) Add

func (e *Circle) Add(new *Circle)

func (*Circle) AddNew

func (e *Circle) AddNew(i int) *Circle

func (*Circle) Remove

func (e *Circle) Remove()

type Combs

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

func NewCombs

func NewCombs(n int, k int) *Combs

func (*Combs) Done

func (c *Combs) Done() bool

func (*Combs) Get

func (c *Combs) Get() []int

func (*Combs) Next

func (c *Combs) Next() []int

type Compass

type Compass string

func (Compass) Direction

func (c Compass) Direction() Direction

func (Compass) Opposite

func (c Compass) Opposite() Compass

type Deque

type Deque[T any] struct {
	// contains filtered or unexported fields
}

func NewDeque

func NewDeque[T any](a []T) *Deque[T]

func (*Deque[T]) IsEmpty

func (d *Deque[T]) IsEmpty() bool

func (*Deque[T]) Len

func (d *Deque[T]) Len() int

func (*Deque[T]) Pop

func (d *Deque[T]) Pop() T

func (*Deque[T]) Push

func (d *Deque[T]) Push(v T)

type Direction

type Direction struct {
	Dx, Dy int
}

func (Direction) CCW

func (d Direction) CCW() Direction

func (Direction) CW

func (d Direction) CW() Direction

func (Direction) Char

func (d Direction) Char() byte

func (Direction) Compass

func (d Direction) Compass() Compass

func (Direction) Opposite

func (d Direction) Opposite() Direction

func (Direction) String

func (d Direction) String() string

type ElfProg2018

type ElfProg2018 struct {
	Prog []*Inst
	IP   int
	Reg  [6]int
	// contains filtered or unexported fields
}

func NewElfProg2018

func NewElfProg2018(lines []string) *ElfProg2018

func (*ElfProg2018) Run

func (g *ElfProg2018) Run(fn func(*ElfProg2018) bool) int

func (*ElfProg2018) String

func (g *ElfProg2018) String() string

type FBoundingBox

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

func NewFBoundingBox

func NewFBoundingBox() *FBoundingBox

func (*FBoundingBox) Add

func (bb *FBoundingBox) Add(p FP2)

func (*FBoundingBox) AddXY

func (bb *FBoundingBox) AddXY(x, y int32)

func (*FBoundingBox) Limits

func (bb *FBoundingBox) Limits() (int32, int32, int32, int32)

func (*FBoundingBox) String

func (bb *FBoundingBox) String() string

func (*FBoundingBox) XLimits

func (bb *FBoundingBox) XLimits() (int32, int32)

func (*FBoundingBox) YLimits

func (bb *FBoundingBox) YLimits() (int32, int32)

type FP2

type FP2 uint64

func NewFP2

func NewFP2(x, y int32) FP2

func (FP2) Add

func (p FP2) Add(o FP2) FP2

func (FP2) CCW

func (p FP2) CCW() FP2

func (FP2) CW

func (p FP2) CW() FP2

func (FP2) ManhattanDistance

func (p FP2) ManhattanDistance(o FP2) int

func (FP2) Norm

func (p FP2) Norm(o FP2) FP2

func (FP2) NormXY

func (p FP2) NormXY(o FP2) (int32, int32)

func (FP2) Rotate

func (p FP2) Rotate(rotation int) FP2

func (FP2) String

func (p FP2) String() string

func (FP2) Sub

func (p FP2) Sub(o FP2) FP2

func (FP2) UKey

func (p FP2) UKey(bits int) uint64

func (FP2) XY

func (p FP2) XY() (int32, int32)

type FP3

type FP3 uint64

func NewFP3

func NewFP3(x, y, z int16) FP3

func (FP3) Add

func (p FP3) Add(o FP3) FP3

func (FP3) ManhattanDistance

func (p FP3) ManhattanDistance(o FP3) int

func (FP3) Norm

func (p FP3) Norm(o FP3) FP3

func (FP3) ProjXY

func (p FP3) ProjXY() FP3

func (FP3) Rotate

func (p FP3) Rotate(rotation int) FP3

func (FP3) String

func (p FP3) String() string

func (FP3) Sub

func (p FP3) Sub(o FP3) FP3

func (FP3) UKey

func (p FP3) UKey(bits int, zbits int) uint64

func (FP3) XYZ

func (p FP3) XYZ() (int16, int16, int16)

type HexPoint

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

func NewHexPoint

func NewHexPoint(q, r int) *HexPoint

func (*HexPoint) Distance

func (h1 *HexPoint) Distance(h2 *HexPoint) int

func (*HexPoint) Move

func (h *HexPoint) Move(dir string)

func (*HexPoint) Neighbours

func (h *HexPoint) Neighbours() []*HexPoint

func (*HexPoint) Q

func (h *HexPoint) Q() int

func (*HexPoint) R

func (h *HexPoint) R() int

func (*HexPoint) X

func (h *HexPoint) X() int

func (*HexPoint) Y

func (h *HexPoint) Y() int

func (*HexPoint) Z

func (h *HexPoint) Z() int

type IDBuilder

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

func NewIDBuilder

func NewIDBuilder(t IDType, l int) *IDBuilder

func (*IDBuilder) Add

func (i *IDBuilder) Add(ch byte) int

func (*IDBuilder) Pretty

func (i *IDBuilder) Pretty(n int) string

func (*IDBuilder) Reset

func (i *IDBuilder) Reset()

func (*IDBuilder) Size

func (i *IDBuilder) Size() int

type IDTracker

type IDTracker interface {
	Add(w []byte) int
	Len() int
	Pretty(n int) string
}

type IDType

type IDType interface {
	Add(p int, ch byte) int
	Char(c int) byte
	Size() int
}

type Inst

type Inst struct {
	Op string
	A  int
	B  int
	C  int
}

func (*Inst) String

func (i *Inst) String() string

type List2IDTracker

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

func NewList2IDTracker

func NewList2IDTracker(l int) *List2IDTracker

func (*List2IDTracker) Add

func (t *List2IDTracker) Add(w []byte) int

func (*List2IDTracker) Len

func (t *List2IDTracker) Len() int

func (*List2IDTracker) Pretty

func (t *List2IDTracker) Pretty(i int) string

type ListIDTracker

type ListIDTracker []int

func NewListIDTracker

func NewListIDTracker(l int) ListIDTracker

func (*ListIDTracker) Add

func (t *ListIDTracker) Add(w []byte) int

func (*ListIDTracker) Len

func (t *ListIDTracker) Len() int

func (*ListIDTracker) Pretty

func (t *ListIDTracker) Pretty(i int) string

type LowerAZID

type LowerAZID struct{}

func (LowerAZID) Add

func (l LowerAZID) Add(p int, ch byte) int

func (LowerAZID) Char

func (l LowerAZID) Char(c int) byte

func (LowerAZID) Size

func (l LowerAZID) Size() int

type MapByteCounter

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

func (*MapByteCounter) Add

func (bc *MapByteCounter) Add(ch byte, c int)

func (*MapByteCounter) Bottom

func (bc *MapByteCounter) Bottom(n int) []byte

func (*MapByteCounter) Count

func (bc *MapByteCounter) Count(ch byte) int

func (*MapByteCounter) Inc

func (bc *MapByteCounter) Inc(ch byte)

func (*MapByteCounter) Top

func (bc *MapByteCounter) Top(n int) []byte

type NumStr

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

func NewNumStr

func NewNumStr(prefix string) *NumStr

func NewNumStrFromBytes

func NewNumStrFromBytes(prefix []byte) *NumStr

func (*NumStr) Bytes

func (n *NumStr) Bytes() []byte

func (*NumStr) Inc

func (n *NumStr) Inc()

func (*NumStr) String

func (n *NumStr) String() string

type PerlyString

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

func NewPerlyString

func NewPerlyString(pw string) *PerlyString

func (*PerlyString) Bytes

func (pw *PerlyString) Bytes() []byte

func (*PerlyString) Inc

func (pw *PerlyString) Inc()

func (*PerlyString) String

func (pw *PerlyString) String() string

type Perms

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

func NewPerms

func NewPerms(n int) *Perms

func (*Perms) Done

func (p *Perms) Done() bool

func (*Perms) Get

func (p *Perms) Get() []int

func (*Perms) Next

func (p *Perms) Next() []int

type Point

type Point struct {
	X, Y int
}

Point is a two dimensional point defined by x and y coordinates

func (*Point) In

func (p *Point) In(d Direction) Point

func (Point) ManhattanDistance

func (p Point) ManhattanDistance(o Point) int

ManhattanDistance returns the Manhattan distance between a 2d point and another 2d point

func (Point) Neighbours

func (p Point) Neighbours() []Point

Neighbours returns the four neighbours of a point

func (Point) Neighbours8

func (p Point) Neighbours8() []Point

Neighbours8 returns the eight neighbours of a point

func (*Point) Norm

func (p *Point) Norm(o *Point) *Point

func (Point) Size

func (p Point) Size() float64

func (Point) String

func (p Point) String() string

type Point3D

type Point3D struct {
	X, Y, Z int
}

func (Point3D) ManhattanDistance

func (p Point3D) ManhattanDistance(o Point3D) int

func (Point3D) Size

func (p Point3D) Size() float64

func (Point3D) String

func (p Point3D) String() string

type PointPair

type PointPair struct {
	P1 *Point
	P2 *Point
}

func (*PointPair) Norm

func (pp *PointPair) Norm() *Point

func (*PointPair) String

func (pp *PointPair) String() string

type Queue

type Queue[T any] struct {
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue[T any](buf []T) *Queue[T]

func (*Queue[T]) Empty

func (q *Queue[T]) Empty() bool

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

func (*Queue[T]) Pop

func (q *Queue[T]) Pop() T

func (*Queue[T]) Push

func (q *Queue[T]) Push(i T)

type SliceByteCounter

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

func (*SliceByteCounter) Add

func (bc *SliceByteCounter) Add(ch byte, c int)

func (*SliceByteCounter) Bottom

func (bc *SliceByteCounter) Bottom(n int) []byte

func (*SliceByteCounter) Count

func (bc *SliceByteCounter) Count(ch byte) int

func (*SliceByteCounter) Inc

func (bc *SliceByteCounter) Inc(ch byte)

func (*SliceByteCounter) Sort

func (bc *SliceByteCounter) Sort()

func (*SliceByteCounter) String

func (bc *SliceByteCounter) String() string

func (*SliceByteCounter) Top

func (bc *SliceByteCounter) Top(n int) []byte

type Subsets

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

func NewSubsets

func NewSubsets(n int) *Subsets

func (*Subsets) Done

func (ss *Subsets) Done() bool

func (*Subsets) Get

func (ss *Subsets) Get() []int

func (*Subsets) Next

func (ss *Subsets) Next() []int

type UpperAZID

type UpperAZID struct{}

func (UpperAZID) Add

func (l UpperAZID) Add(p int, ch byte) int

func (UpperAZID) Char

func (l UpperAZID) Char(c int) byte

func (UpperAZID) Size

func (l UpperAZID) Size() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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