Added Len{,64} gives back the number of digits of a number.
This commit is contained in:
parent
29de09a237
commit
d1c3f6619b
@ -62,6 +62,28 @@ func IsPalindromic(n int) bool {
|
|||||||
return true
|
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.
|
// Permutations returns all possible permutations of the the set integers.
|
||||||
func Permutations(set []int) [][]int {
|
func Permutations(set []int) [][]int {
|
||||||
var n = len(set)
|
var n = len(set)
|
||||||
|
Loading…
Reference in New Issue
Block a user