util

package
v0.0.0-...-ee7795c Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(x int) int

Abs returns the mathematical absolute value of a given integer

func Delta

func Delta(x, y int) int

Delta returns the delta between given integers x and y

func Handle

func Handle(err error)

Handle calls log.Fatal on an error

func ManhattanDistance

func ManhattanDistance(a, b Point) int

ManhattanDistance returns the manhattan distance between two points (delta between x's plus delta between y's)

func NewLine

func NewLine() string

NewLine returns "\n" for non-windows and "\r\n" for windows runtime

func ToInt

func ToInt(s string) int

ToInt converts a string to an int and calls log.Fatal on an error

Types

type File

type File []byte

File is a file as bytearray

func ReadFile

func ReadFile(path string) File

ReadFile reads a file into the File struct ([]byte) and calls log.Fatal on an error

func (File) AsLines

func (f File) AsLines() Lines

AsLines returns the lines of a file as Lines type ([]string)

func (File) WithOSLinebreaks

func (f File) WithOSLinebreaks() File

WithOSLinebreaks returns the File with OS-specific linebreaks instead of LF (for testing purposes)

type Line

type Line string

Line is a string

func (Line) AsInt

func (l Line) AsInt() int

AsInt converts a line to int and calls log.Fatal on an error

func (Line) SubSplitWith

func (l Line) SubSplitWith(separator string) Lines

SubSplitWith splits a Line on into Lines using the given separator

type Lines

type Lines []Line

Lines is an array of Line

func (Lines) As2DInts

func (lines Lines) As2DInts(separator string) [][]int

As2DInts converts Lines ([]string) to [][]int, splitting the line on the given separator

func (Lines) AsInts

func (lines Lines) AsInts() []int

AsInts converts Lines ([]string) to []int

type Point

type Point struct {
	X, Y int
}

func (*Point) Neighbours

func (n *Point) Neighbours(maxX, maxY int) []Point

Neighbours returns direct neighbours on x and y axis (no diagonal neighbours)

func (*Point) NeighboursWithDiagonal

func (n *Point) NeighboursWithDiagonal(maxX, maxY int) []Point

Neighbours returns direct neighbours on x and y axis as well as diagonal neighbours

Jump to

Keyboard shortcuts

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