Compare commits
2 Commits
9215311802
...
d1c3f6619b
Author | SHA1 | Date | |
---|---|---|---|
d1c3f6619b | |||
29de09a237 |
10
ints/math.go
10
ints/math.go
@ -72,6 +72,16 @@ func Norm64(i int64) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// NthRoot returns the nth root of i.
|
||||
func NthRoot(i, n int) int {
|
||||
return int(math.Pow(float64(i), 1/float64(n)))
|
||||
}
|
||||
|
||||
// NthRoot64 returns the nth root of i.
|
||||
func NthRoot64(i, n int64) int64 {
|
||||
return int64(math.Pow(float64(i), 1/float64(n)))
|
||||
}
|
||||
|
||||
// SubAbs subtracts a from b and returns the absolute value of the result.
|
||||
func SubAbs(a, b int) int {
|
||||
if a > b {
|
||||
|
@ -62,6 +62,28 @@ func IsPalindromic(n int) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Len returns the number of digits of i (base 10, does not include a sign).
|
||||
func Len(i int) int {
|
||||
return Len64(int64(i))
|
||||
}
|
||||
|
||||
// Len64 returns the number of digits of i (base 10, does not include a sign).
|
||||
func Len64(i int64) int {
|
||||
if i == 0 {
|
||||
return 1
|
||||
}
|
||||
if i < 0 {
|
||||
i = 0 - i
|
||||
}
|
||||
|
||||
digits := 0
|
||||
for i > 0 {
|
||||
i /= 10
|
||||
digits++
|
||||
}
|
||||
return digits
|
||||
}
|
||||
|
||||
// Permutations returns all possible permutations of the the set integers.
|
||||
func Permutations(set []int) [][]int {
|
||||
var n = len(set)
|
||||
|
Loading…
Reference in New Issue
Block a user