Perl Monk, Perl Meditation  
PerlMonks 
(crazyinsomniac) Re: (2) Binomial Expansionby crazyinsomniac (Prior) 
on Mar 31, 2001 at 04:41 UTC ( #68580=note: print w/replies, xml )  Need Help?? 
I take great offense in calling my nCr function horribly inaccurate. You do say right away that is a valid formula for binomial coefficients, but then you say it's hardly a good one? It is a formula for calculating rcombinations, not binomial coefficients. The formula for binomial expansion is: n _ (x+y)^n = \ C(n,j) * x^(nj) *y^j / ¯ j=0 And btw, it is the definitive formula for calculating rcombinations. It's like saying 4/2 is not the same as 2. While 2 is a better way to write 4/2, not every one recognizes 2 right away, and I feel, for the benefit of the reader of me 'craft', n!/(r!(nr)! is a better way to go. As for your function, it is shorter, but a litle mysterious when it comes to the math. update:9! 9*8*7* 6! 9*8*7 504 nCr(9,3) =  =  =  =  = 84 3!*(93)! 3*2*1*(6!) 3*2*1 6 which follows from the fact that nCr(n,r) = nCr(n,nr) n! n! n! _ n!  =  =  =  r!(nr) (nr)!(n(nr))! (nr)!(nn+r)! (nr)!(r)!This however only works for n>r, as long as n and r are both nonnegative integers, but shouldn't be a problem in this case. I give, I give, theory v. practice, there is a difference.
In Section
Craft

