Cody

# Problem 43166. Probabilities - Balls and urns - 02

Solution 1724177

Submitted on 11 Feb 2019
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
R=4; B=8; N=6; K=2; p = 0.4545; assert( abs(probability(R,B,N,K)-p)<1e-04 );

2   Pass
R=22; B=6; N=14; K=12; p = 0.2418; assert( abs(probability(R,B,N,K)-p)<1e-04 );

3   Fail
R=22; B=60; N=5; K=0; p = 0.2002; assert( abs(probability(R,B,N,K)-p)<1e-04 );

Error using nchoosek (line 29) The second input has to be a non-negative integer. Error in probability (line 2) p = nchoosek(R,R-K)*nchoosek(B,N-R+K)/nchoosek(R+B,N); Error in Test3 (line 4) assert( abs(probability(R,B,N,K)-p)<1e-04 );

4   Fail
R=9; B=0; N=4; K=4; assert( isequal(probability(R,B,N,K),1) );

Error using nchoosek (line 29) The second input has to be a non-negative integer. Error in probability (line 2) p = nchoosek(R,R-K)*nchoosek(B,N-R+K)/nchoosek(R+B,N); Error in Test4 (line 3) assert( isequal(probability(R,B,N,K),1) );

5   Fail
R=1; B=78; N=78; K=1; p = 0.9873; assert( abs(probability(R,B,N,K)-p)<1e-04 );

Assertion failed.