Documentation
¶
Overview ¶
Package tools Generic function for math, Array, Insert etc
Index ¶
- func AbsInt(x int) int
- func BigIntToBinStr(b *big.Int) string
- func BinStrAdd(s, a string) *big.Int
- func BinStrToBigInt(s string) *big.Int
- func Copy2dInt(src [][]int) (des [][]int)
- func EqualMatrix(a, b [][]int) (res bool)
- func EucliDistSquared(x1, y1, x2, y2 int) int
- func InsertAt[K comparable](inp []K, position int, value []K) (res []K, err error)
- func InsertIntAt(inp []int, position int, value []int) (res []int, err error)
- func MaxInt(x, y int) int
- func MinInt(x, y int) int
- func Square(n int) int
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BigIntToBinStr ¶
BigIntToBinStr Rerturn a big.Int as a String with binary value
func BinStrAdd ¶
BinStrAdd add to string with binary valued and returns it sum as Big.Int Example BinStrAdd("111101","10") returns "111111" return 0 convert error and print "SetString: Error"
Example ¶
one := BinStrAdd("11101", "10")
fmt.Println(BigIntToBinStr(one))
two := BinStrAdd(BigIntToBinStr(one), "1")
fmt.Println(BigIntToBinStr(two))
Output: 11111 100000
func BinStrToBigInt ¶
BinStrToBigInt return "101010" return Big.Int with 101010 stored as int
func EqualMatrix ¶
EqualMatrix return two are the same [][]int
func EucliDistSquared ¶
EucliDistSquared return part of euclidean distance (x1 - x2)2 + (y1 - y2)2
The full is euclidean distance is (sqrt) √(x1 - x2)2 + (y1 - y2)2) but this function is meant to be used to compare the short distance so if the answer is square 2 too big does not matter.
If the correct euclidean distance is need remember to int(math.Ceil(float64(EucliDistSquared(x,y)))) the result
Example fmt.Println(EucliDistSquared(0,0,1,3)) // OutPut : 10
log.Println(math.Ceil(math.Sqrt(float64(EucliDistSquared(0, 0, 1, 3))))) // This is the real distans // OutPut : 4
func InsertAt ¶
func InsertAt[K comparable](inp []K, position int, value []K) (res []K, err error)
InsertAt insert []genric at position in array
func InsertIntAt ¶
InsertIntAt insert []int at position in array
Example ¶
a := []int{1, 2, 3}
fmt.Println("Array before:", a)
res, err := InsertIntAt(a, 0, []int{51, 56, 57})
if err != nil {
fmt.Println(err)
}
fmt.Println("After insert 3 int in pos 0:", res)
Output: Array before: [1 2 3] After insert 3 int in pos 0: [51 56 57 1 2 3]
Types ¶
This section is empty.