aoc

package
v0.0.0-...-58dcd34 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

This example demonstrates a priority queue built using the heap interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	Neighbors2d4 = []Point2d{
		0 + 1i,
		0 + -1i,
		1 + 0i,
		-1 + 0i,
	}
	Neighbors2d8 = []Point2d{
		0 + 1i,
		0 + -1i,
		1 + 0i,
		-1 + 0i,
		1 + 1i,
		1 + -1i,
		-1 + 1i,
		-1 + -1i,
	}
)

Functions

func Abs

func Abs[X constraints.Integer](x X) X

func All

func All[X bool](xs ...X) bool

func AllEq

func AllEq[X comparable](xs ...X) bool

func AllFunc

func AllFunc[X any](f func(x X) bool, xs ...X) bool

func Any

func Any[X bool](xs ...X) bool

func AnyFunc

func AnyFunc[X any](f func(x X) bool, xs ...X) bool

func Area

func Area(a Point2d, b Point2d) int64

func Copy

func Copy[X any](slice []X) []X

func Count

func Count[X comparable](slice []X, needle X) int

func Delete

func Delete[X comparable](slice []X, el X) []X

func DeleteAt

func DeleteAt[X any](slice []X, s int) []X

func DoEachNeighbor

func DoEachNeighbor[X any](f func(n Point2d) X, c Point2d, ns []Point2d) []X

func EnclosedAreaWithinPath

func EnclosedAreaWithinPath(path []Point2d) int64

func EuclidianDistance

func EuclidianDistance(a Point2d, b Point2d) float64

func Filter

func Filter[X any](filter func(x X) bool, xs []X) []X

func FilterMap

func FilterMap[X any, M any](f func(x X) (M, bool), xs []X) []M

func Find

func Find[X comparable](slice []X, el X) int

func GCD

func GCD[X constraints.Integer](a, b X) X

func Int

func Int(x string) int

Int64 returns int64 from the given string or panics

func Int64

func Int64(x string) int64

Int64 returns int64 from the given string or panics

func IntFromHex

func IntFromHex(x string) int

func LCM

func LCM[X constraints.Integer](xs ...X) X

func Last

func Last[X any](xs []X) X

func ManhattenDistance

func ManhattenDistance(a Point2d, b Point2d) int64

func Map

func Map[X any, M any](f func(x X) M, xs []X) []M

func Max

func Max[X constraints.Ordered](xs ...X) X

Min returns the maximum value in xs xs must be non-empty or it'll panic.

func MaxWithKey

func MaxWithKey[X any, Y constraints.Ordered](key func(X) Y, xs ...X) X

func Min

func Min[X constraints.Ordered](xs ...X) X

Min returns the minimum value in xs xs must be non-empty or it'll panic.

func Mul

func Mul[N Number](xs []N) N

func ParseInt64List

func ParseInt64List(s string) []int64

func Reduce

func Reduce[X any, A any](reducer func(acc A, x X) A, xs []X, init A) A

func ReduceReverse

func ReduceReverse[X any, A any](reducer func(acc A, x X) A, xs []X, init A) A

func Repeat

func Repeat[X any](slice []X, n int) []X

func RepeatWithSeparator

func RepeatWithSeparator[X any](slice []X, n int, sep X) []X

func Reverse

func Reverse[X any](slice []X) []X

func RotateCounterClockwise

func RotateCounterClockwise[X any](slice [][]X) [][]X

func Sum

func Sum[N Number](xs []N) N

func SumFunc

func SumFunc[N Number, Y any](f func(acc N, y Y) N, xs []Y) N

func SumMap

func SumMap[N Number, X any](f func(x X) N, xs []X) N

func Transpose

func Transpose[X any](slice [][]X) [][]X

func Zip

func Zip[X any](xss ...[]X) [][]X

Types

type Counter

type Counter[A comparable] map[A]int

func NewCounter

func NewCounter[A comparable](xs []A) Counter[A]

func (Counter[A]) Values

func (c Counter[A]) Values() []int

type Grid2d

type Grid2d[X comparable, Y comparable] map[X]Y

func NewGrid2d

func NewGrid2d[X comparable, Y comparable]() Grid2d[X, Y]

func ParseGrid2d

func ParseGrid2d[Y comparable](input io.Reader, v func(x rune) Y) Grid2d[Point2d, Y]

func (Grid2d[X, Y]) Add

func (g Grid2d[X, Y]) Add(p X, v Y)

func (Grid2d[X, Y]) Find

func (g Grid2d[X, Y]) Find(v Y) (X, bool)

func (Grid2d[X, Y]) FindOrPanic

func (g Grid2d[X, Y]) FindOrPanic(v Y) X

func (Grid2d[X, Y]) Walk

func (g Grid2d[X, Y]) Walk(start X, end X, nextF func(cur X, prev X) X) []X

type Hashed

type Hashed uint64

func Hash

func Hash[X any](x X) Hashed

type Item

type Item[X any] struct {
	Value    X   // The value of the item; arbitrary.
	Priority int // The priority of the item in the queue.
	// contains filtered or unexported fields
}

An Item is something we manage in a priority queue.

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type Pair

type Pair[A any, B any] struct {
	A A
	B B
}

Pair is a dead-simple 2-value pair.

func DistinctValueCombinations

func DistinctValueCombinations[X comparable](xs []X) []Pair[X, X]

func NewPair

func NewPair[A any, B any](a A, b B) Pair[A, B]

type Point2d

type Point2d complex128

Point2d is just a very simple wrapper around a complex128 The x, y coordinates are stored in the real and imag parts of the complex number. The complex number is used to easily have comparable types and easily support properties like addition and substraction of points.

func AllNeighborCoords

func AllNeighborCoords(c Point2d, ns []Point2d) []Point2d

func NewPoint2d

func NewPoint2d[X Number](x, y X) Point2d

func (Point2d) X

func (p Point2d) X() int64

func (Point2d) Y

func (p Point2d) Y() int64

type PriorityQueue

type PriorityQueue[X any] []*Item[X]

A PriorityQueue implements heap.Interface and holds Items.

func (PriorityQueue[X]) Len

func (pq PriorityQueue[X]) Len() int

func (PriorityQueue[X]) Less

func (pq PriorityQueue[X]) Less(i, j int) bool

func (*PriorityQueue[X]) Pop

func (pq *PriorityQueue[X]) Pop() any

func (*PriorityQueue[X]) Push

func (pq *PriorityQueue[X]) Push(x any)

func (PriorityQueue[X]) Swap

func (pq PriorityQueue[X]) Swap(i, j int)

type Set

type Set[X comparable] map[X]struct{}

func NewSet

func NewSet[X comparable](xs ...X) Set[X]

func (Set[X]) Add

func (s Set[X]) Add(x X)

func (Set[X]) Apply

func (s Set[X]) Apply(f func(x X) X)

func (Set[X]) Contains

func (s Set[X]) Contains(x X) bool

func (Set[X]) Copy

func (s Set[X]) Copy() Set[X]

func (Set[X]) Del

func (s Set[X]) Del(x X) (existed bool)

func (Set[X]) Difference

func (s Set[X]) Difference(other Set[X]) Set[X]

Difference returns the elements that are in s, but not in other

func (Set[X]) Extend

func (s Set[X]) Extend(xs ...X)

func (Set[X]) Intersection

func (s Set[X]) Intersection(other Set[X]) Set[X]

Intersection returns the elemtsn that are common in s and other

func (Set[X]) IsDisjoint

func (s Set[X]) IsDisjoint(other Set[X]) bool

IsDisjoint returns true if no element of s are in other

func (Set[X]) IsSubSet

func (s Set[X]) IsSubSet(other Set[X]) bool

IsSubSet returns wether s is a subset of other

func (Set[X]) IsSuperSet

func (s Set[X]) IsSuperSet(other Set[X]) bool

IsSuperSet returns wether s is a superset of other

func (Set[X]) SymmetricDifference

func (s Set[X]) SymmetricDifference(other Set[X]) Set[X]

SymmetricDifference returns the elements that are either in s or other, but not in both

func (Set[X]) ToSlice

func (s Set[X]) ToSlice() []X

func (Set[X]) Union

func (s Set[X]) Union(other Set[X]) Set[X]

Union returns the elements of both s and other combined

type Triple

type Triple[A any, B any, C any] struct {
	A A
	B B
	C C
}

func NewTriple

func NewTriple[A any, B any, C any](a A, b B, c C) Triple[A, B, C]

Jump to

Keyboard shortcuts

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