Documentation ¶
Index ¶
- func Abs[T constraints.Integer | constraints.Float](n T) T
- func AllDirection(y, x, rows, cols int) [][2]int
- func CardinalDirection(y, x, rows, cols int) [][]int
- func Digits(n int) <-chan int
- func MatrixCopy(dest, src [][]int)
- func Max[T constraints.Integer | constraints.Float](x, y T) T
- func Min[T constraints.Integer | constraints.Float](x, y T) T
- func MinMax(sl []int) (int, int)
- func Mod[T constraints.Integer](a, b T) T
- func MustAtoi(s string) int
- func MustBtoi(s string) int
- func MustParseInt(s string, base int, bitSize int) int64
- func ReadLines(path string) ([]string, error)
- func ReadLinesAsInt(path string) ([]int, error)
- func ReadSections(path string) ([][]string, error)
- func Reverse[T any](sl []T)
- func Signum[T constraints.Integer | constraints.Float](n T) T
- func SortString(s string) string
- func Sum[T constraints.Integer | constraints.Float | constraints.Complex](arr []T) T
- func SumN[T constraints.Integer](n T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[T constraints.Integer | constraints.Float](n T) T
Abs returns an absolute value of the given integer or floating-point number.
func AllDirection ¶
AllDirection is similar to CardinalDirection except this returns coordinates in all the directions from a given point, excluding the given point.
func CardinalDirection ¶
CardinalDirection returns a list of coordinates in the four cardinal directions from the given point (x, y).
The list contains only the coordinates which are within the matrix bounds as given by the rows and cols argument. The four cardinal directions are: North, South, East and West.
func Digits ¶
Digits is used to iterate over each digit of the given number from left to right. This returns a channel from which you can only receive an integer one at a time and can be used in various ways like so:
for d := range Digits(123) { // do something with d } ch := Digits(123) // ... other code fmt.Println(<-ch) // ... other code fmt.Println(<-ch)
func MatrixCopy ¶
func MatrixCopy(dest, src [][]int)
MatrixCopy is used to copy integer slice elements from source slice to a destination slice. Internally, this uses the built-in copy function to copy individual slice elements.
func Max ¶
func Max[T constraints.Integer | constraints.Float](x, y T) T
Max returns the larger of x or y.
func Min ¶
func Min[T constraints.Integer | constraints.Float](x, y T) T
Min returns the smaller of x or y.
func MinMax ¶
MinMax returns the minimum and maximum value in the given slice of integers. This will panic if the slice is empty.
func Mod ¶
func Mod[T constraints.Integer](a, b T) T
Mod returns a % b, specifically the least positive remainder. This is different than the builtin % operator which returns the least negative remainder. This should only be used if either a or b is negative. Mod behaves the same as the builtin % operator when both a and b are positive.
func MustParseInt ¶
MustParseInt is like strconv.ParseInt but panics if the parsing fails.
func ReadLines ¶
ReadLines is used to read the content of the file at a given path into a string slice where each element corresponds to a single line.
func ReadLinesAsInt ¶
ReadLinesAsInt is similar to ReadLines, except this will convert each line into an integer and return an int slice instead.
func ReadSections ¶
ReadSections is used to read the content of the file at a given path by sections. A section is defined as being separated by two newlines and each section is then converted into string slice where each element corresponds to a single line of that section.
func Reverse ¶
func Reverse[T any](sl []T)
Reverse reverses the order of elements in the given slice in place.
func Signum ¶
func Signum[T constraints.Integer | constraints.Float](n T) T
Returns a number representing sign of n.
- 0 if the number is zero
- 1 if the number is positive
- -1 if the number is negative
func SortString ¶
SortString is used to sort the individual characters in the given string.
func Sum ¶
func Sum[T constraints.Integer | constraints.Float | constraints.Complex](arr []T) T
Sum is used to add all the integers in a given array.
Types ¶
This section is empty.