From 3be706e23f292e0fef1abe39b41304cbc69771ce Mon Sep 17 00:00:00 2001 From: dudaodong Date: Tue, 19 Nov 2024 10:25:32 +0800 Subject: [PATCH] doc: add doc for Permutation and Combination function --- docs/api/packages/mathutil.md | 90 ++++++++++++++++++++++++++++---- docs/en/api/packages/mathutil.md | 68 ++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 11 deletions(-) diff --git a/docs/api/packages/mathutil.md b/docs/api/packages/mathutil.md index 0f07daa..ff9389b 100644 --- a/docs/api/packages/mathutil.md +++ b/docs/api/packages/mathutil.md @@ -33,7 +33,7 @@ import ( - [Percent](#Percent) - [RoundToFloat](#RoundToFloat) - [RoundToString](#RoundToString) -- [TruncRound](#TruncRound) +- [T运行cRound](#T运行cRound) - [CeilToFloat](#CeilToFloat) - [CeilToString](#CeilToString) - [FloorToFloat](#FloorToFloat) @@ -54,6 +54,8 @@ import ( - [Div](#Div) - [Variance](#Variance) - [StdDev](#StdDev) +- [Permutation](#Permutation) +- [Combination](#Combination)
@@ -464,14 +466,14 @@ func main() { } ``` -### TruncRound +### T运行cRound

截短n位小数(不进行四舍五入)

函数签名: ```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 ``` 示例:[运行](https://go.dev/play/p/aumarSHIGzP) @@ -485,9 +487,9 @@ import ( ) func main() { - result1 := mathutil.TruncRound(0.124, 2) - result2 := mathutil.TruncRound(0.125, 2) - result3 := mathutil.TruncRound(0.125, 3) + result1 := mathutil.T运行cRound(0.124, 2) + result2 := mathutil.T运行cRound(0.125, 2) + result3 := mathutil.T运行cRound(0.125, 3) fmt.Println(result1) fmt.Println(result2) @@ -1047,8 +1049,8 @@ import ( func main() { result1 := mathutil.Log(8, 2) - result2 := mathutil.TruncRound(mathutil.Log(5, 2), 2) - result3 := mathutil.TruncRound(mathutil.Log(27, 3), 0) + result2 := mathutil.T运行cRound(mathutil.Log(5, 2), 2) + result3 := mathutil.T运行cRound(mathutil.Log(27, 3), 0) fmt.Println(result1) fmt.Println(result2) @@ -1209,7 +1211,7 @@ func main() { func StdDev[T constraints.Float | constraints.Integer](numbers []T) float64 ``` -示例:[Run](todo) +示例:[运行](todo) ```go package main @@ -1220,8 +1222,8 @@ import ( ) func main() { - result1 := mathutil.TruncRound(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) + result1 := mathutil.T运行cRound(mathutil.StdDev([]int{1, 2, 3, 4, 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(result2) @@ -1230,4 +1232,70 @@ func main() { // 1.41 // 1.55 } +``` + +### Permutation + +

计算排列数(P(n, k))。

+ +函数签名: + +```go +func Permutation(n, k uint) uint +``` + +示例:[运行](todo) + +```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 +} +``` + +### Combination + +

计算组合数(C(n, k))。

+ +函数签名: + +```go +func Combination(n, k uint) uint +``` + +示例:[运行](todo) + +```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 +} ``` \ No newline at end of file diff --git a/docs/en/api/packages/mathutil.md b/docs/en/api/packages/mathutil.md index 6d1ac0f..38486c4 100644 --- a/docs/en/api/packages/mathutil.md +++ b/docs/en/api/packages/mathutil.md @@ -54,6 +54,8 @@ import ( - [Div](#Div) - [Variance](#Variance) - [StdDev](#StdDev) +- [Permutation](#Permutation) +- [Combination](#Combination)
@@ -1229,4 +1231,70 @@ func main() { // 1.41 // 1.55 } +``` + +### Permutation + +

Calculates P(n, k).

+ +Signature: + +```go +func Permutation(n, k uint) uint +``` + +Example:[Run](todo) + +```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 +} +``` + +### Combination + +

Calculates C(n, k).

+ +Signature: + +```go +func Combination(n, k uint) uint +``` + +Example:[Run](todo) + +```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 +} ``` \ No newline at end of file