maths

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	N = iota
	E
	S
	W
	NE
	SE
	SW
	NW
)

Variables

View Source
var ALL_MOVES = []Position{
	{X: -1, Y: 0},
	{X: 0, Y: 1},
	{X: 1, Y: 0},
	{X: 0, Y: -1},
	{X: -1, Y: 1},
	{X: 1, Y: 1},
	{X: 1, Y: -1},
	{X: -1, Y: -1},
}
View Source
var HORIZONTAL_MOVES = []Position{
	{X: -1, Y: 0},
	{X: 0, Y: 1},
	{X: 1, Y: 0},
	{X: 0, Y: -1},
}

Functions

func CountDigits

func CountDigits(num int) int

func Gcd

func Gcd[T Number](a, b T) T

func GenerateHash

func GenerateHash(values ...interface{}) uint64

func InitTypeGrid

func InitTypeGrid[T any](val T, height, width int) [][]T

func Lcm

func Lcm[T Number](a, b T) T

func LcmRange

func LcmRange[T Number](vals ...T) T

func Max

func Max[T AnyNum](a, b T) T

func ToInt

func ToInt(s string) int

func ToInt64

func ToInt64(s string) int64

func Transpose

func Transpose[T any](matrix [][]T) [][]T

Types

type AnyNum

type AnyNum interface {
	int | float32 | float64
}

type Number

type Number interface {
	int | int8 | int16 | int32 | int64
}

type Position

type Position struct {
	X int
	Y int
}

func GetNeighbors

func GetNeighbors(position Position) []Position

func NewPosition

func NewPosition(row int, col int) Position

func (Position) Add

func (p Position) Add(other Position) Position

func (Position) Distance

func (p Position) Distance(other Position) float64

func (Position) EvaluateFor

func (p Position) EvaluateFor(grid [][]int) int

func (Position) InBounds

func (p Position) InBounds(size int) bool

func (Position) OutOfBounds

func (p Position) OutOfBounds(size int) bool

func (*Position) PAdd

func (p *Position) PAdd(o Position)

func (*Position) PMinus

func (p *Position) PMinus(o Position)

Jump to

Keyboard shortcuts

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