in reply to Binomial Expansion
The nCr function above is horribly inaccurate. While n!/r!(n-r)! is indeed a valid formula for binomial coefficients, it's hardly a good way to calculate them. Here's a better way:
Why $res remains an integer (for "reasonable" parameter values) remains an exercise for the reader...sub nCr { my ($n, $r) = @_; my $res = 1; for my $i (1..$r) { $res *= $n--; $res /= $i; } $res; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Binomial Expansion
by japhy (Canon) on Mar 29, 2001 at 21:39 UTC | |
(crazyinsomniac) Re: (2) Binomial Expansion
by crazyinsomniac (Prior) on Mar 31, 2001 at 04:41 UTC | |
by tye (Sage) on Mar 31, 2001 at 12:26 UTC | |
by tilly (Archbishop) on Mar 31, 2001 at 23:32 UTC | |
by tilly (Archbishop) on Apr 01, 2001 at 05:26 UTC | |
by tye (Sage) on Apr 01, 2001 at 08:09 UTC | |
by tilly (Archbishop) on Apr 01, 2001 at 18:56 UTC | |
by ariels (Curate) on Apr 11, 2001 at 10:55 UTC |
In Section
Craft