gint

package module
v0.0.0-...-d4686d0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2021 License: MIT Imports: 2 Imported by: 0

README

Useful Go functions

See on pkg.go.dev

go get -u -v github.com/wasmup/gint

Example:

package main

import (
	"fmt"

	"github.com/wasmup/gint"
	"github.com/wasmup/gint/bigint"
	"github.com/wasmup/gint/iface"
	"github.com/wasmup/gint/u32"
	"github.com/wasmup/gint/u64"
	"github.com/wasmup/gint/u8"
)

func main() {
	fmt.Println(u8.Max(2, 4, 7, 9, 0)) // 9

	fmt.Println(u32.MinMax(2, 4, 7, 9, 0)) // 0 9

	fmt.Println(gint.MinMax(-2, 4, 7, 9, 0)) // -2 9

	fmt.Println(u8.GCD(24, 48, 72)) // 24

	a := []byte{1, 2, 3, 4}
	fmt.Println(u8.MinMax(a...)) // 1 4

	u8.Reverse(a)
	fmt.Println(a) // [4 3 2 1]

	fmt.Println(u8.Sum(a...)) // 10

	b := []interface{}{1, 2, 2, 2}
	b = iface.Distinct(b)
	fmt.Println(b) // [1 2]

	fmt.Println(u64.Factorial(12)) // 479001600

	fmt.Println(bigint.Factorial(100))
	// 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000

}

Documentation

Index

Constants

View Source
const (

	// KB is kilobyte and equal to 1024 which is 11bit.
	KB = 1 << (iota * 10)
	// MB is megabyte and equal to 1024 KB=1048576 which is 21bit.
	MB = 1 << (iota * 10)
	// GB is gigabyte and equal to 1024 MB=1073741824 which is 31bit.
	GB = 1 << (iota * 10)
	// TB is terabyte and equal to 1024 GB=1099511627776 which is 41bit.
	TB = 1 << (iota * 10)

	// PB is petabyte and equal to 1024 TB=1125899906842624 which is 51bit.
	PB = 1 << (iota * 10)
	// EB is exabyte and equal to 1024 PB=1152921504606846976 which is 61bit.
	EB = 1 << (iota * 10)
	// ZB is zettabyte and equal to 1024 EB=1180591620717411303424 which is 71bit.
	ZB = 1 << (iota * 10)
	// YB is yottabyte and equal to 1024 ZB=1208925819614629174706176 which is 81bit.
	YB = 1 << (iota * 10)
)

Variables

This section is empty.

Functions

func Abs

func Abs(n int) int

Abs returns none negative number.

func Distinct

func Distinct(a []int) (r []int)

Distinct returns a new slice with all duplicate values removed.

func Factorial

func Factorial(n int) int

Factorial returns factorial(n) n must be positive.

32 bit int: 0 <= n <= 12 otherwise panics. 12! = 479,001,600 = 0x1C8C FC00 == 29bit 13! = 6,227,020,800 = 0x1 7328 cc00 == 33bit

64 bit int:

0 <= n <= 20 otherwise panics.

20! = 2,432,902,008,176,640,000 = 0x21C3 677C 82B4 0000 == 62bit 21! = 51,090,942,171,709,440,000 = 0x2 C507 7D36 B8C4 0000 == 66bit

func GCD

func GCD(a ...int) int

GCD returns greatest common divisor

func GCD2

func GCD2(m, n int) int

GCD2 returns greatest common divisor

func Insert

func Insert(a []int, index int, value int) []int

Insert the value at the index of the slice 0 <= index <= len(a)

func IsPrime

func IsPrime(n int) bool

IsPrime returns true for a prime number e.g 2,3,5,7,11,...

func Max

func Max(a ...int) int

Max returns a maximum of all input arguments

func Max2

func Max2(a, b int) int

Max2 returns a if a >= b else b

func Memset

func Memset(a []int, value int)

Memset fills the slice with the value.

func Min

func Min(a ...int) int

Min returns a minimum of all input arguments

func Min2

func Min2(a, b int) int

Min2 returns a if a <= b else b

func MinMax

func MinMax(a ...int) (int, int)

MinMax returns a (minimum, maximum) of all input arguments

func MinMax2

func MinMax2(a, b int) (int, int)

MinMax2 returns a (minimum, maximum) of input arguments

func Mul

func Mul(a ...int) int

Mul returns mul of all input values

func Primes

func Primes(max int) []int

Primes returns all primes <= max:

func Remove

func Remove(a []int, index int) []int

Remove the value at the index.

func Reverse

func Reverse(a []int)

Reverse the slice in place.

func Sum

func Sum(a ...int) int

Sum returns sum of all input values

func Thousands

func Thousands(n int) string

Thousands returns thousands separated by underline e.g.: 1_234_567

func TimeRun

func TimeRun(f func()) time.Duration

TimeRun returns the realtime of running f().

Types

This section is empty.

Directories

Path Synopsis
Package combinations provides primitives for selection of one element per row, from collections, such that (unlike permutations) the order of selection does not matter.
Package combinations provides primitives for selection of one element per row, from collections, such that (unlike permutations) the order of selection does not matter.
primes command
Package kcombinations provides primitives for selection of k items from a collection of n items, such that (unlike permutations) the order of selection does not matter.
Package kcombinations provides primitives for selection of k items from a collection of n items, such that (unlike permutations) the order of selection does not matter.
examples/simple command
Package permutations provides primitives for selection of elements for a collection permutations (ordered selection).
Package permutations provides primitives for selection of elements for a collection permutations (ordered selection).
examples command
examples/str command

Jump to

Keyboard shortcuts

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