intmath

package
v0.0.0-...-06eecd2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(i int) int

Abs returns the absolute value of a number.

func Atoi

func Atoi(s string) int

Atoi returns the integer value of a string or panics.

func Factors

func Factors(n int) []int

Factors returns a sorted slice of all of the factors of a given number.

func Gcd

func Gcd(a, b int) int

Gcd returns the greatest common denominator of two numbers. https://play.golang.org/p/SmzvkDjYlb

func Lcm

func Lcm(a, b int, integers ...int) int

Lcm returns the least common multiple of two numbers.

func Max

func Max(in ...int) int

Max returns the minimum value provided.

func Min

func Min(in ...int) int

Min returns the minimum value provided.

func Mod

func Mod(a, b int) int

Mod returns a positive number as other languages.

func Permutations

func Permutations(in []int) <-chan []int

Permutations returns all of the permutations of a given slice of ints.

func Product

func Product(i ...int) int

Product returns the product of all provided values.

func Sqrt

func Sqrt(i int) int

Sqrt returns floor(sqrt(i)).

func Sum

func Sum(i ...int) (ret int)

Sum returns the sum of all provided values.

Types

type Bitmap

type Bitmap struct {
	// contains filtered or unexported fields
}

Bitmap provides a simple implementation of a 64 bit bitmap

func (Bitmap) AndEq

func (b Bitmap) AndEq(o Bitmap) bool

AndEq bitwise ANDs the values and returns true if the result matches the called Bitmap.

func (Bitmap) OneBits

func (b Bitmap) OneBits() (ret []int)

OneBits returns the cardinal value of all bits set to 1.

func (Bitmap) Set

func (b Bitmap) Set(i int) Bitmap

Set sets the n-th bit to 1.

func (Bitmap) String

func (b Bitmap) String() string

String returns a string representation of the Bitmap.

func (Bitmap) Unset

func (b Bitmap) Unset(i int) Bitmap

Unset sets the n-th bit to 0.

func (Bitmap) Val

func (b Bitmap) Val() uint64

Val exposes the underlying int value of the Bitmap.

type Point

type Point struct {
	X, Y int
}

Point is a point in Cartesian space.

func (Point) AllNeighbors

func (p Point) AllNeighbors() (ret []Point)

AllNeighbors returns the neighboring points in all directions. This function returns points in reading order.

func (Point) ContainedIn

func (p Point) ContainedIn(topLeft, bottomRight Point) bool

ContainedIn determines if this point is within a rectangle described by two points.

func (Point) ManhattanDistanceTo

func (p Point) ManhattanDistanceTo(op Point) int

ManhattanDistanceTo computes the distance between two points on a grid.

func (Point) Neighbor

func (p Point) Neighbor(dir rune) (op Point)

Neighbor returns a new point in a given directon. Valid directions are UDLR or NSEW (case insensitive).

func (Point) Neighbors

func (p Point) Neighbors() (ret []Point)

Neighbors returns the neighboring points in horizontal and vertical directions. This function returns points in reading order.

Jump to

Keyboard shortcuts

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