mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-04 12:52:28 +08:00
doc: add doc for Permutation and Combination function
This commit is contained in:
@@ -33,7 +33,7 @@ import (
|
|||||||
- [Percent](#Percent)
|
- [Percent](#Percent)
|
||||||
- [RoundToFloat](#RoundToFloat)
|
- [RoundToFloat](#RoundToFloat)
|
||||||
- [RoundToString](#RoundToString)
|
- [RoundToString](#RoundToString)
|
||||||
- [TruncRound](#TruncRound)
|
- [T运行cRound](#T运行cRound)
|
||||||
- [CeilToFloat](#CeilToFloat)
|
- [CeilToFloat](#CeilToFloat)
|
||||||
- [CeilToString](#CeilToString)
|
- [CeilToString](#CeilToString)
|
||||||
- [FloorToFloat](#FloorToFloat)
|
- [FloorToFloat](#FloorToFloat)
|
||||||
@@ -54,6 +54,8 @@ import (
|
|||||||
- [Div](#Div)
|
- [Div](#Div)
|
||||||
- [Variance](#Variance)
|
- [Variance](#Variance)
|
||||||
- [StdDev](#StdDev)
|
- [StdDev](#StdDev)
|
||||||
|
- [Permutation](#Permutation)
|
||||||
|
- [Combination](#Combination)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -464,14 +466,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### <span id="TruncRound">TruncRound</span>
|
### <span id="T运行cRound">T运行cRound</span>
|
||||||
|
|
||||||
<p>截短n位小数(不进行四舍五入)</p>
|
<p>截短n位小数(不进行四舍五入)</p>
|
||||||
|
|
||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func TruncRound[T constraints.Float | constraints.Integer](x T, n int) T
|
func T运行cRound[T constraints.Float | constraints.Integer](x T, n int) T
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/aumarSHIGzP)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](https://go.dev/play/p/aumarSHIGzP)</span></b>
|
||||||
@@ -485,9 +487,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := mathutil.TruncRound(0.124, 2)
|
result1 := mathutil.T运行cRound(0.124, 2)
|
||||||
result2 := mathutil.TruncRound(0.125, 2)
|
result2 := mathutil.T运行cRound(0.125, 2)
|
||||||
result3 := mathutil.TruncRound(0.125, 3)
|
result3 := mathutil.T运行cRound(0.125, 3)
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
@@ -1047,8 +1049,8 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := mathutil.Log(8, 2)
|
result1 := mathutil.Log(8, 2)
|
||||||
result2 := mathutil.TruncRound(mathutil.Log(5, 2), 2)
|
result2 := mathutil.T运行cRound(mathutil.Log(5, 2), 2)
|
||||||
result3 := mathutil.TruncRound(mathutil.Log(27, 3), 0)
|
result3 := mathutil.T运行cRound(mathutil.Log(27, 3), 0)
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
@@ -1209,7 +1211,7 @@ func main() {
|
|||||||
func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64
|
func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64
|
||||||
```
|
```
|
||||||
|
|
||||||
<b>示例:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
@@ -1220,8 +1222,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := mathutil.TruncRound(mathutil.StdDev([]int{1, 2, 3, 4, 5}), 2)
|
result1 := mathutil.T运行cRound(mathutil.StdDev([]int{1, 2, 3, 4, 5}), 2)
|
||||||
result2 := mathutil.TruncRound(mathutil.StdDev([]float64{1.1, 2.2, 3.3, 4.4, 5.5}), 2)
|
result2 := mathutil.T运行cRound(mathutil.StdDev([]float64{1.1, 2.2, 3.3, 4.4, 5.5}), 2)
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
@@ -1231,3 +1233,69 @@ func main() {
|
|||||||
// 1.55
|
// 1.55
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="Permutation">Permutation</span>
|
||||||
|
|
||||||
|
<p>计算排列数(P(n, k))。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Permutation(n, k uint) uint
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/mathutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := mathutil.Permutation(5, 3)
|
||||||
|
result2 := mathutil.Permutation(5, 5)
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 60
|
||||||
|
// 120
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Combination">Combination</span>
|
||||||
|
|
||||||
|
<p>计算组合数(C(n, k))。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Combination(n, k uint) uint
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:<span style="float:right;display:inline-block;">[运行](todo)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/mathutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := mathutil.Combination(5, 3)
|
||||||
|
result2 := mathutil.Combination(5, 5)
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 10
|
||||||
|
// 1
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -54,6 +54,8 @@ import (
|
|||||||
- [Div](#Div)
|
- [Div](#Div)
|
||||||
- [Variance](#Variance)
|
- [Variance](#Variance)
|
||||||
- [StdDev](#StdDev)
|
- [StdDev](#StdDev)
|
||||||
|
- [Permutation](#Permutation)
|
||||||
|
- [Combination](#Combination)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -1230,3 +1232,69 @@ func main() {
|
|||||||
// 1.55
|
// 1.55
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="Permutation">Permutation</span>
|
||||||
|
|
||||||
|
<p>Calculates P(n, k).</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Permutation(n, k uint) uint
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/mathutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := mathutil.Permutation(5, 3)
|
||||||
|
result2 := mathutil.Permutation(5, 5)
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 60
|
||||||
|
// 120
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### <span id="Combination">Combination</span>
|
||||||
|
|
||||||
|
<p>Calculates C(n, k).</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func Combination(n, k uint) uint
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:<span style="float:right;display:inline-block;">[Run](todo)</span></b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/mathutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
result1 := mathutil.Combination(5, 3)
|
||||||
|
result2 := mathutil.Combination(5, 5)
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 10
|
||||||
|
// 1
|
||||||
|
}
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user