June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -13,11 +13,9 @@ double Factorial(double nValue)
|
|||
return nValue;
|
||||
}
|
||||
|
||||
double EvaluateBinomialCoefficient(double nValue, double nValue2)
|
||||
double binomialCoefficient(double n, double k)
|
||||
{
|
||||
double result;
|
||||
if(nValue2 == 1)return nValue;
|
||||
result = (Factorial(nValue))/(Factorial(nValue2)*Factorial((nValue - nValue2)));
|
||||
nValue2 = result;
|
||||
return nValue2;
|
||||
if (abs(n - k) < 1e-7 || k < 1e-7) return 1.0;
|
||||
if( abs(k-1.0) < 1e-7 || abs(k - (n-1)) < 1e-7)return n;
|
||||
return Factorial(n) /(Factorial(k)*Factorial((n - k)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
int main()
|
||||
{
|
||||
cout<<"The Binomial Coefficient of 5, and 3, is equal to: "<< EvaluateBinomialCoefficient(5,3);
|
||||
cout<<"The Binomial Coefficient of 5, and 3, is equal to: "<< binomialCoefficient(5,3);
|
||||
cin.get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
choose(N, 0) -> 1;
|
||||
choose(N, K) when is_integer(N), is_integer(K), (N >= 0), (K >= 0), (N >= K) ->
|
||||
choose(N, K, 1, 1).
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
@show binomial(5, 3)
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
function binom(n::Integer, k::Integer)
|
||||
n ≥ k || return 0 # short circuit base cases
|
||||
n == 1 || k == 0 && return 1
|
||||
|
||||
return (n * binom(n - 1, k - 1)) ÷ k
|
||||
end
|
||||
|
||||
@show binom(5, 3)
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
function binom(n,k)
|
||||
n >= k || return 0 #short circuit base cases
|
||||
n == 1 && return 1
|
||||
k == 0 && return 1
|
||||
|
||||
(n * binom(n - 1, k - 1)) ÷ k #recursive call
|
||||
end
|
||||
|
||||
julia> binom(5,2)
|
||||
10
|
||||
Loading…
Add table
Add a link
Reference in a new issue