mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(mathutil): compute permutations without factorial division (#364)
Co-authored-by: DuDaoDong <dudaodong@gmail.com>
This commit is contained in:
1 parent
9555cb2fc5
commit
5774d0e95e
1 file changed
+5
-4
@@ -438,10 +438,11 @@ func Permutation(n, k uint) uint {
|
||||
return 0
|
||||
}
|
||||
|
||||
nFactorial := Factorial(n)
|
||||
nMinusKFactorial := Factorial(n - k)
|
||||
|
||||
return nFactorial / nMinusKFactorial
|
||||
result := uint(1)
|
||||
for i := uint(0); i < k; i++ {
|
||||
result *= n - i
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Combination calculate C(n, k).
|
||||
|
||||
Reference in new issue
Block a user