aoc

package
v0.0.0-...-6284559 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T constraints.Integer | constraints.Float](x T) T

func All

func All[T any](in []T, allFn func(T) bool) bool

All returns a bool indicating if all values in the input slice produce a true value when evaluated by allFn

func Any

func Any[T any](in []T, anyFn func(T) bool) bool

Any returns a bool indicating if any value in the input slice produce a true value when evaluated by anyFn

func Atoi

func Atoi(a string) int

func Atoi64

func Atoi64(a string) int64

func Carve

func Carve[T any](in []T, i, j int) []T

func Chunk

func Chunk[T any](in []T, size int) [][]T

func Combinations

func Combinations[T any](in []T) [][2]T

Combinations return a slice of tuples of all 2 value combinations of the input slice

func Concat

func Concat[V any](seqs ...iter.Seq[V]) iter.Seq[V]

func Cons

func Cons[T any](in []T, offset int) [][2]T

Cons take an input slice and an offset and loops though the slice making a tuple of index and index+offset

func Count

func Count[T any](in []T, countFn func(T) bool) int

Count returns an int of the number if values in the input slice that return true when evaluated by countFn

func Cycle

func Cycle[T any](s iter.Seq[T]) iter.Seq[T]

func Each

func Each[T any](in []T, f func(T))

func EachMap

func EachMap[T comparable, V any](in map[T]V, f func(T, V))

func GCD

func GCD(a, b int) int

func IPow

func IPow(base, exp int64) int64

func Includes

func Includes[T comparable](in []T, value T) bool

Includes returns true if any value in the input slice matches value

func Intersection

func Intersection[T comparable](x ...[]T) []T

func Join

func Join[T any](in []T, sep string) string

func KeyWithMaxValue

func KeyWithMaxValue[T comparable, V constraints.Ordered](in map[T]V) T

KeyWithMaxValue takes a map and returns the key in the map that is associated with the maximum value. As maps are read in random order if the maximum value is shared the returned k is not deterministic

func KeyWithValue

func KeyWithValue[T comparable, V comparable](in map[T]V, val V) T

func LCM

func LCM(nums []int) int

func Map

func Map[T any, V any](in []T, f func(T) V) []V

Map takes an input slice and a mapping function and returns a slice of values as modified by f

func MapM

func MapM[T comparable, V any](in []T, f func(T) (T, V)) map[T]V

func MapMap

func MapMap[T comparable, V any, X comparable, Y any](in map[T]V, f func(T, V) (X, Y)) map[X]Y

func MapWithIndex

func MapWithIndex[T any, V any](in []T, f func(int, T) V) []V

func Max

func Max[T constraints.Ordered](in []T) T

Max returns the maximum value in the input slice

func MaxWithIndex

func MaxWithIndex[T constraints.Ordered](in []T) (int, T)

MaxWithIndex returns the index of, and the maximum value in the input slice

func Min

func Min[T constraints.Ordered](in []T) T

Min returns the minimum value in the input slice

func MinMax

func MinMax[T constraints.Ordered](in []T) (T, T)

MinMax returns two values, the minimum and maximum value in the input slice

func MinWithIndex

func MinWithIndex[T constraints.Ordered](in []T) (int, T)

MinWithIndex returns the minimum value in the input slice

func Partition

func Partition[T any](in []T, partFn func(T) bool) ([]T, []T)

Partition takes an input slice and returns two slices using partFn to decide which it goes in, the first return value is the slice of values that return true when evaluated by partFn the second return is those that return false

func Permutations

func Permutations[T any](in []T) [][]T

func Product

func Product[T constraints.Integer | constraints.Float](in []T) T

Product returns the product of values in the input slice

func Reduce

func Reduce[T any, A any](in []T, initial A, reduceFn func(A, T) A) A

Reduce takes an input slice, and initial value and a reduce function it passes every value in the input slice to the reduceFn and returns the final value returned by reduceFn

func Reject

func Reject[T any](in []T, f func(T) bool) []T

Select returns a slice of the input values that return false when evalueted by f

func Repeat

func Repeat[T any](x T, i int) []T

func Reverse

func Reverse[T any](in []T) []T

func Select

func Select[T any](in []T, f func(i T) bool) []T

Select returns a slice of the input values that return true when evalueted by f

func SelectMap

func SelectMap[T comparable, V any](in map[T]V, f func(i T, j V) bool) map[T]V

func Sign

func Sign[T constraints.Integer | constraints.Float](x T) T

func Sort

func Sort[T constraints.Ordered](in []T) []T

func SubSlice

func SubSlice[T comparable](a, b []T) []T

func Sum

func Sum[T constraints.Integer | constraints.Float](in []T) T

Sum returns the sum of values in the input slice

func Tally

func Tally[T comparable](in []T) map[T]int

Tally takes a slice of comparable items and returns a map with a tally of the number of times each item appears in the slice

func Union

func Union[T comparable](x []T, y []T) []T

Union return a slice of the unique union of the input slices

func Zip

func Zip[T any](in ...[]T) [][]T

Zip take a variadic number of input slices and produces a single output slice of tuples of the ith value of each input slice

Types

type Point

type Point struct {
	X int64
	Y int64
}

func (*Point) Add

func (p *Point) Add(b Point) Point

func (*Point) Line

func (p *Point) Line(b Point) []Point

func (*Point) MDistance

func (p *Point) MDistance(b Point) int64

func (*Point) MDistanceXY

func (p *Point) MDistanceXY(x, y int64) int64

func (*Point) Neighbour

func (p *Point) Neighbour(b Point) bool

func (*Point) Sub

func (p *Point) Sub(b Point) Point

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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