Statistics

Problem Statement for "MarbleBag"

Problem Statement

You have a bag filled with some number of red, blue and green marbles. You begin picking marbles randomly from the bag. What is the probability that the last marble you select is green?

Definition

Class:
MarbleBag
Method:
getProbability
Parameters:
int, int, int
Returns:
double
Method signature:
double getProbability(int red, int blue, int green)
(be sure your method is public)

Constraints

  • red will be between 0 and 100, inclusive.
  • blue will be between 0 and 100, inclusive.
  • green will be between 0 and 100, inclusive.
  • There will be at least one marble in the bag.

Examples

  1. 1

    1

    1

    Returns: 0.3333333333333333

    The last marble is equally likely to be any of the three, so there's a 1/3 chance it's green.

  2. 0

    0

    100

    Returns: 1.0

    Since the bag only has green marbles, the last one is guaranteed to be green.

  3. 100

    100

    0

    Returns: 0.0

  4. 3

    4

    5

    Returns: 0.4166666666666667

  5. 63

    27

    48

    Returns: 0.34782608695652173

  6. 100

    100

    100

    Returns: 0.3333333333333333


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: