utils

package
v0.0.0-...-8124729 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs[T signed](num T) T

func All

func All[T any](arr []T, cb func(x T, i int) bool) bool

python's all() function, kinda

func GetSignPoint

func GetSignPoint(point image.Point) image.Point

convert vector into a sign vector ex: {4,0} -> {1,0} and {0,-4} -> {0,-1}

func ManhattanDistance

func ManhattanDistance(a, b image.Point) int

func Max

func Max[T numeric](nums ...T) T

func Min

func Min[T numeric](nums ...T) T

func ParseInt

func ParseInt(str string) int

panics if int cannot be parsed from string

func ReadEmptyLineGroups

func ReadEmptyLineGroups(file string) (content []string)

splits and trims file to return empty-new-line-separated groups

func ReadFile

func ReadFile(file string) (content string)

read entire file as a string

func ReadInts

func ReadInts(file string) (content []int)

read lines into []int

func ReadLines

func ReadLines(file string) (lines []string)

read lines into []string

func ReadLinesFunc

func ReadLinesFunc[T comparable](file string, parser func(s string) T) (lines []T)

helper for parsing lines of text from a file

func RunSolvers

func RunSolvers[T any, O any](day Day[T, O])

abstract boilerplate to run solvers for each day

Types

type Day

type Day[T any, O any] struct {
	FileReader func(string) T
	Fncs       []func(T) O
}

A day is just a file reader and the functions to call with the input content

Jump to

Keyboard shortcuts

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