From 5774d0e95e7d376f846d11cf4eda477966db603a Mon Sep 17 00:00:00 2001 From: Yusuf Efe <120668197+yuefdev@users.noreply.github.com> Date: Sat, 24 Oct 2026 17:50:03 +0300 Subject: [PATCH] fix(mathutil): compute permutations without factorial division (#364) Co-authored-by: DuDaoDong --- mathutil/mathutil.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mathutil/mathutil.go b/mathutil/mathutil.go index ac933be..f246acd 100644 --- a/mathutil/mathutil.go +++ b/mathutil/mathutil.go @@ -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).