utilities

package
v0.0.0-...-e61498d Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: Unlicense Imports: 3 Imported by: 0

Documentation

Overview

Package utilities contains utility functions for Advent of Code solutions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt

func AbsInt(x int) int

AbsInt returns the absolute value of an integer.

func ConvertStringSliceToIntSlice

func ConvertStringSliceToIntSlice(s []string) ([]int, error)

ConvertStringSliceToIntSlice converts a slice of strings to a slice of ints.

func Filter

func Filter[T any](s []T, f func(T) bool) []T

Filter returns a slice with only elements that match the predicate.

func GCD

func GCD(a, b int) int

greatest common divisor (GCD) via Euclidean algorithm

func LCM

func LCM(a, b int) int

least common multiple (LCM)

func Map

func Map[T, U any](s []T, f func(T) U) []U

Map applies a function to each element of a slice. ref: https://github.com/sa-/slicefunk/blob/66981647c9612b24c7030d60edcb1215e43c4467/main.go#L3

func MaxFloatSlice

func MaxFloatSlice(arr []float64) float64

MaxFloatSlice returns the maximum value of a slice of floats.

func MeanFloatSlice

func MeanFloatSlice(arr []float64) float64

MeanFloatSlice returns the mean of a slice of floats.

func MinFloatSlice

func MinFloatSlice(arr []float64) float64

MinFloatSlice returns the minimum value of a slice of floats.

func Unique

func Unique[T comparable](s []T) []T

Unique returns a slice with only unique elements.

Types

type Point2D

type Point2D struct {
	X, Y int
}

func (Point2D) Add

func (p Point2D) Add(m Point2D) Point2D

func (Point2D) EuclideanDistance

func (p Point2D) EuclideanDistance(m Point2D) float64

func (Point2D) ManhattanDistance

func (p Point2D) ManhattanDistance(m Point2D) int

func (Point2D) String

func (p Point2D) String() string

func (Point2D) Sub

func (p Point2D) Sub(m Point2D) Point2D

type Point3D

type Point3D struct {
	X, Y, Z int
}

func (Point3D) Add

func (p Point3D) Add(m Point3D) Point3D

func (Point3D) String

func (p Point3D) String() string

func (Point3D) Sub

func (p Point3D) Sub(m Point3D) Point3D

Jump to

Keyboard shortcuts

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