tools

package
v0.0.0-...-eb8a366 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Unlicense Imports: 2 Imported by: 0

Documentation

Overview

Package tools Generic function for math, Array, Insert etc

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsInt

func AbsInt(x int) int

AbsInt 1=1 -1=1 (by doing -1 * -1 = 1)

func BigIntToBinStr

func BigIntToBinStr(b *big.Int) string

BigIntToBinStr Rerturn a big.Int as a String with binary value

func BinStrAdd

func BinStrAdd(s, a string) *big.Int

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

func BinStrToBigInt(s string) *big.Int

BinStrToBigInt return "101010" return Big.Int with 101010 stored as int

func Copy2dInt

func Copy2dInt(src [][]int) (des [][]int)

Copy2dInt make copy [][]int 2d array.

func EqualMatrix

func EqualMatrix(a, b [][]int) (res bool)

EqualMatrix return two are the same [][]int

func EucliDistSquared

func EucliDistSquared(x1, y1, x2, y2 int) int

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

func InsertIntAt(inp []int, position int, value []int) (res []int, err error)

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]

func MaxInt

func MaxInt(x, y int) int

MaxInt bigest number of x, y in int

func MinInt

func MinInt(x, y int) int

MinInt smallest number of x, y in int

func Square

func Square(n int) int

Square return n*n.

Types

This section is empty.

Directories

Path Synopsis
Package ds Data Store, Data Structors Exempel NodeTree,Pos,Rune Stack
Package ds Data Store, Data Structors Exempel NodeTree,Pos,Rune Stack

Jump to

Keyboard shortcuts

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