Problem Statement
You are playing a game in which you draw 9 marbles from a bag. You win the game if at least 5 of them are the same color.
You are given the
Calculate and return the probability that you will win the game.
Definition
- Class:
- MarbleDrawGame
- Method:
- winningChance
- Parameters:
- int[]
- Returns:
- double
- Method signature:
- double winningChance(int[] marbles)
- (be sure your method is public)
Notes
- Your returned answer must be within 1e-9 absolute or relative error to be considered correct.
- Assume that the probability distribution is uniform: each set of nine marbles is equally likely to be selected.
Constraints
- marbles will contain between 1 and 50 elements, inclusive.
- Each element of marbles will be between 1 and 50, inclusive.
- The total number of marbles will be between 9 and 50, inclusive.
Examples
{ 5, 5 }
Returns: 1.0
There are only two colors of marbles, with five of each color. Regardless of which nine you pick, you are guaranteed to get five of one color (and four of the other).
{ 3, 4, 3 }
Returns: 0.0
There are no five marbles of the same color, so you can't win.
{ 1, 1, 1, 1, 1, 5 }
Returns: 0.5
You will either draw five of the same color and four others that don't match, or else five that don't match and four of the same color. There is an equal chance of either outcome.
{5, 4, 1}
Returns: 0.5
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 0.0
{50}
Returns: 1.0
{ 40, 5, 5 }
Returns: 0.9900606030804168
{ 3, 4, 5, 6 }
Returns: 0.08031674208144797
{10, 10 }
Returns: 1.0
{3, 4, 5, 6 }
Returns: 0.08031674208144797
{8, 8, 9, 10, 11, 4 }
Returns: 0.03773875157821977
{10, 10, 10, 10, 10 }
Returns: 0.05029167205661838
{3, 4, 3 }
Returns: 0.0
{9, 1 }
Returns: 1.0
{5, 5 }
Returns: 1.0
{6, 6, 6, 6, 6, 6, 6, 6 }
Returns: 0.0032582781975032905
{10, 12, 19 }
Returns: 0.49006311847057904
{7, 1, 1, 1 }
Returns: 1.0
{50 }
Returns: 1.0
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
Returns: 0.0
{6, 1, 1, 1 }
Returns: 1.0
{1, 1, 1, 1, 1, 5 }
Returns: 0.5
{9 }
Returns: 1.0
{43, 6, 1 }
Returns: 0.9992611458846427
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
Returns: 0.0