Statistics

Problem Statement for "MarbleDrawGame"

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 int[] marbles. Each element of marbles represents the number of marbles of one color. For example, if there are 7 red, 3 green and 50 blue marbles in the bag, we could have marbles = {7, 3, 50}.

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

  1. { 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).

  2. { 3, 4, 3 }

    Returns: 0.0

    There are no five marbles of the same color, so you can't win.

  3. { 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.

  4. {5, 4, 1}

    Returns: 0.5

  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

  6. {50}

    Returns: 1.0

  7. { 40, 5, 5 }

    Returns: 0.9900606030804168

  8. { 3, 4, 5, 6 }

    Returns: 0.08031674208144797

  9. {10, 10 }

    Returns: 1.0

  10. {3, 4, 5, 6 }

    Returns: 0.08031674208144797

  11. {8, 8, 9, 10, 11, 4 }

    Returns: 0.03773875157821977

  12. {10, 10, 10, 10, 10 }

    Returns: 0.05029167205661838

  13. {3, 4, 3 }

    Returns: 0.0

  14. {9, 1 }

    Returns: 1.0

  15. {5, 5 }

    Returns: 1.0

  16. {6, 6, 6, 6, 6, 6, 6, 6 }

    Returns: 0.0032582781975032905

  17. {10, 12, 19 }

    Returns: 0.49006311847057904

  18. {7, 1, 1, 1 }

    Returns: 1.0

  19. {50 }

    Returns: 1.0

  20. {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }

    Returns: 0.0

  21. {6, 1, 1, 1 }

    Returns: 1.0

  22. {1, 1, 1, 1, 1, 5 }

    Returns: 0.5

  23. {9 }

    Returns: 1.0

  24. {43, 6, 1 }

    Returns: 0.9992611458846427

  25. {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


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: