Statistics

Problem Statement for "WinningProbability"

Problem Statement

You favorite sports team is heading into a big playoff series against its big rival. They've gone head to head a number of times previously, and the inputs, prevWins and prevLosses, summarize the results. Now, there are gamesLeft games left in the series, and your team must win at least mustWin of them in order to win the series. You want to know what the probability is that they will accomplish this.

To that end, you've come up with the following strategy. First, you will assume that there is some probability, p, that your team will win each game, and you will assume that each game is independent. For a given value of p, you can thus calculate the probability that your team won and lost as it did in the past. Now, let's say that for a given value of p, p1, the probability of the previous games turning out as they did is q1, and similarly for p2, the probability is q2. From this, you've decided that the true probability of your team winning a game is (q1/q2) times more likely to be p1 than it is to be p2. Considering all possible values of p, and taking into account the relative probabilities of each, determine the probability that your team will win the series.

Definition

Class:
WinningProbability
Method:
probability
Parameters:
int, int, int, int
Returns:
double
Method signature:
double probability(int prevWins, int prevLosses, int gamesLeft, int mustWin)
(be sure your method is public)

Notes

  • Your return must have an error of less than 1e-9.

Constraints

  • prevWins and prevLosses will each be between 0 and 100, inclusive.
  • gamesLeft will be between 1 and 15, inclusive.
  • mustWin will be between 1 and gamesLeft, inclusive.

Examples

  1. 2

    0

    1

    1

    Returns: 0.75

    Consider a few illustrative values of p: | prob of | prob of p | previous | winning series ----+----------+--------------- 0.0 | 0.0 | 0.0 0.1 | 0.01 | 0.1 0.2 | 0.04 | 0.2 0.3 | 0.09 | 0.3 0.4 | 0.16 | 0.4 0.5 | 0.25 | 0.5 0.6 | 0.36 | 0.6 0.7 | 0.49 | 0.7 0.8 | 0.64 | 0.8 0.9 | 0.81 | 0.9 1.0 | 1.0 | 1.0 So, p is 4 times more likely to be 1.0 than it is to be 0.5, and is definitely not 0. Considering only these values of p, and taking a weighted average, we find that the probability of winning the series is 0.786. Clearly, considering only 11 values of p does not yield the required accuracy, but if you consider all possible values, you find that your team has a probability of 0.75 of winning the series.

  2. 0

    3

    4

    4

    Returns: 0.0142857142857

    After losing the first 3 games of the ALCS, the Red Sox had a probability of less than 2% of winning the series, according to this model.

  3. 20

    3

    5

    1

    Returns: 0.9995284409077

    Your team only needs to win 1 out of 5 games, and in the past it has won 20/23, so your odds are high.

  4. 0

    20

    1

    1

    Returns: 0.0454545454545

    Your team has never won in the past, so its unlikely they will this time.

  5. 0

    0

    1

    1

    Returns: 0.5

    With no previous games, all values of p are equally likely, and as you would expect, there is a 50% chance that your team will win.

  6. 100

    99

    7

    4

    Returns: 0.5053622927646

  7. 0

    100

    15

    1

    Returns: 0.1293103448276

  8. 20

    20

    4

    2

    Returns: 0.6790697674418

  9. 78

    54

    12

    3

    Returns: 0.9950934183886

  10. 100

    77

    4

    4

    Returns: 0.1039720508716

  11. 90

    80

    2

    2

    Returns: 0.2813550208361

  12. 41

    25

    9

    7

    Returns: 0.2812915191208

  13. 49

    6

    3

    2

    Returns: 0.9543511027715

  14. 47

    74

    10

    6

    Returns: 0.1595323998988

  15. 96

    41

    11

    7

    Returns: 0.7775095151468

  16. 50

    99

    2

    2

    Returns: 0.1155454862321

  17. 53

    41

    11

    7

    Returns: 0.43516880005

  18. 16

    76

    4

    1

    Returns: 0.5435344777825

  19. 20

    68

    11

    3

    Returns: 0.4864983176967

  20. 59

    4

    2

    2

    Returns: 0.8531468531469

  21. 30

    20

    10

    2

    Returns: 0.9962239869676

  22. 66

    89

    4

    3

    Returns: 0.2142039205366

  23. 74

    87

    4

    4

    Returns: 0.0467559298995

  24. 38

    48

    8

    8

    Returns: 0.0021466953109

  25. 77

    42

    12

    4

    Returns: 0.9912607771874

  26. 51

    85

    12

    1

    Returns: 0.9955060793368

  27. 100

    100

    15

    7

    Returns: 0.6898945883485

  28. 98

    76

    15

    12

    Returns: 0.0590339352084


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: