Statistics

Problem Statement for "Pitches"

Problem Statement

A struggling baseball pitcher is hoping to improve his results by analyzing the statistics of how various batters perform against each of his two types of pitches: his "fast ball" and his "curve ball". He has developed a model to help him decide which pitch to select in any given circumstance.

In the game of baseball (slightly simplified for this problem), each pitch thrown will result in one of three outcomes: a "strike", a "ball", or a "hit". If a batter ever gets a hit or accumulates 4 balls before accumulating 3 strikes, this is a victory for the batter. However, if he gets 3 strikes first, this is a victory for the pitcher. The running count of balls and strikes is collectively referred to as the "count".

For this analysis, both the pitcher and batter are modelled as having a table of probabilities computed before the game. For each of the 12 possible counts, the pitcher has a probability for selecting to throw a curve ball instead of a fast ball. Similarly, for each possible count, the batter has a probability for expecting the pitcher to throw a curve ball. Before each pitch, the pitcher randomly selects which pitch to throw and the batter randomly selects which pitch to expect strictly according to the probabilities in the table for the current count.

Computing the optimal values for the probabilities in this table depends on the statistics for how the batter performs for each of the 4 possible combinations of thrown and expected pitches. These statistics will be provided by an 8-element double[], stats, in the following form:

    pitcher throws   batter expects   ball      strike    hit
    --------------   --------------   --------  --------  -----------------------
    fast ball        fast ball        stats[0]  stats[1]  1 - (stats[0]+stats[1])
    fast ball        curve ball       stats[2]  stats[3]  1 - (stats[2]+stats[3])
    curve ball       fast ball        stats[4]  stats[5]  1 - (stats[4]+stats[5])
    curve ball       curve ball       stats[6]  stats[7]  1 - (stats[6]+stats[7])

The pitcher attempts to maximize his chance of getting 3 strikes, knowing that the batter will be attempting to maximize his chance of getting 4 balls or a hit. For a given count, the optimal probability for the pitcher to throw a curve ball is the probability that minimizes the batter's ability to succeed. Similarly, the optimal probability for the batter to expect a curve ball is the probability that minimizes the pitcher's ability to succeed. In other words, the optimal pair of probabilities for a given count are such that if either the pitcher's or the batter's probability were to change, the other would be able to improve their chances by changing their probability as well. The optimal pair of probabilities forms an equilibrium, where neither the batter nor the pitcher can improve their chances if the other does not change their probability.

For example, consider the following (unrealistic) statistics: { 0, 0, 0, 1, 0, 1, 0, 0 }, with a count of 3 balls and 2 strikes. In this case, if the batter expects the same pitch that the pitcher throws, he will get a hit, otherwise, it will be a strike. The optimal probabilities are for both the pitcher and batter to select a curve ball exactly 50% of the time. 50% is optimal for the pitcher because if he were to prefer one pitch or the other, the batter could improve his performance by preferring that same pitch. Similarly, 50% is optimal for the batter because if he preferred one pitch or the other, the pitcher would be able to take advantage of that fact by preferring the opposite pitch.

Given the statistics in the format described above as a double[] stats and the current number of balls and strikes, compute the probability that the pitcher will get a total of 3 strikes before the batter gets a hit or a total of 4 balls.

Definition

Class:
Pitches
Method:
strikeOut
Parameters:
double[], int, int
Returns:
double
Method signature:
double strikeOut(double[] stats, int balls, int strikes)
(be sure your method is public)

Notes

  • Your return value must have an absolute or relative error less than 1e-9.

Constraints

  • stats will contain exactly 8 elements.
  • Each element of stats will be between 0.0 and 1.0, inclusive.
  • stats[0] + stats[1] will be less than or equal to 1.0.
  • stats[2] + stats[3] will be less than or equal to 1.0.
  • stats[4] + stats[5] will be less than or equal to 1.0.
  • stats[6] + stats[7] will be less than or equal to 1.0.
  • balls will be between 0 and 3, inclusive.
  • strikes will be between 0 and 2, inclusive.

Examples

  1. { 0, 0, 0, 1, 0, 1, 0, 0 }

    3

    2

    Returns: 0.5

    This is the example in the problem statement.

  2. {0.541360678953378,0.251311079561226,0.810364006439709,0.172433517475874,0.224491762214985,0.40885541054179,0.586207954897386,0.118656938732521}

    0

    0

    Returns: 0.06393930309319609

  3. {0.576011612426814,0.418368878292426,0.00659910848814249,0.466372046112021,0.289294236388617,0.280864375524416,0.556361780182097,0.382662625898313}

    0

    0

    Returns: 0.1949923005099184

  4. { 0, 0, 0, 0.51, 0, 1, 0, 0.49 }

    3

    2

    Returns: 0.5

  5. { 0.375, 0.25, 0.375, 0.25, 0.375, 0.25, 0.375, 0.25 }

    0

    2

    Returns: 0.39208984375

  6. { 0, 0, 0, 0, 0, 0, 0, 1 }

    2

    1

    Returns: 0.0

  7. { 0.33, 0, 0, 1, 0.44, 0, 0, 1 }

    2

    1

    Returns: 0.0

    It doesn't matter which pitch the pitcher throws; if the batter expects a fast ball, he will always get a ball or a hit.

  8. { 0, 1, 0, 1, 0, 0, 0, 0 }

    2

    1

    Returns: 1.0

    It doesn't matter which pitch the batter expects; if the pitcher throws a fast ball, he will always get a strike.

  9. { 0, 0.5, 0, 0, 0, 0, 0, 0.5 }

    1

    1

    Returns: 0.0625

  10. { 0, 0.4, 0.05, 0.75, 0.2, 0.7, 0.85, 0.1 }

    0

    0

    Returns: 0.32194802205218886

  11. {0.046,0.046,0.046,0.046,0.046,0.046,0.046,0.046}

    0

    0

    Returns: 1.1209888882495999E-4

  12. {0.264,0.389,0.242,0.389,0.251,0.389,0.418,0.389}

    0

    0

    Returns: 0.14019653097450774

  13. {0.262,0.319,0.601,0.319,0.576,0.319,0.486,0.25}

    0

    0

    Returns: 0.13921041179085655

  14. {0.139,0.162,0.682,0.162,0.455,0.162,0.237,0.389}

    0

    0

    Returns: 0.019340684483310003

  15. {0.02,0.485,0.169,0.485,0.377,0.439,0.22,0.439}

    0

    0

    Returns: 0.18662321614905125

  16. {0.413,0.431,0.286,0.431,0.616,0.244,0.056,0.431}

    0

    0

    Returns: 0.20677969244686692

  17. {0.008,0.382,0.363,0.382,0.372,0.355,0.208,0}

    0

    0

    Returns: 0.07267762409605114

  18. {0.204,0.353,0.147,0.353,0.727,0.152,0.336,0.211}

    0

    0

    Returns: 0.07048557781436769

  19. {0.67,0.176,0.083,0.176,0.219,0.037,0.595,0.367}

    0

    0

    Returns: 0.021552986306934228

  20. {0.246,0.05,0.028,0.05,0.241,0.101,0.309,0.05}

    0

    0

    Returns: 3.493652862500001E-4

  21. {0.367,0.017,0.653,0.017,0.645,0.318,0.494,0.318}

    0

    0

    Returns: 0.16566717379053886

  22. {0.72,0.099,0.065,0.099,0.476,0.236,0.714,0.076}

    0

    0

    Returns: 0.0051374113568896235

  23. {0.286,0.244,0.742,0.244,0.372,0.34,0.304,0.275}

    0

    0

    Returns: 0.08675955241817294

  24. {0.047,0.081,0.469,0.081,0.079,0.269,0.088,0.31}

    0

    0

    Returns: 0.024903200883376518

  25. {0.578,0.395,0.094,0.224,0.774,0.224,0.579,0.224}

    0

    0

    Returns: 0.07518603007655936

  26. {0.134,0.366,0.57,0.261,0.598,0.261,0.554,0.366}

    0

    0

    Returns: 0.13983521193903417

  27. {0.21,0.419,0.803,0.187,0.547,0.187,0.441,0.087}

    0

    0

    Returns: 0.0800709794625522

  28. {0.358,0.289,0.844,0.01,0.335,0.01,0.586,0.203}

    0

    0

    Returns: 0.01243702310799791

  29. {0.191,0.15,0.182,0.114,0.017,0.114,0.318,0.387}

    0

    0

    Returns: 0.005474707149656154

  30. {0.377,0.437,0.542,0.237,0.303,0.437,0.197,0.237}

    0

    0

    Returns: 0.07961652530415864

  31. {0.4,0.396,0.606,0.151,0.425,0.396,0.371,0.396}

    0

    0

    Returns: 0.214210603868089

  32. {0.424,0.4,0.403,0.154,0.064,0.4,0.2,0.129}

    0

    0

    Returns: 0.01401725143207928

  33. {0.503,0.443,0.549,0.074,0.463,0.443,0.146,0.101}

    0

    0

    Returns: 0.002899747636088471

  34. {0.391,0.358,0.739,0.192,0.067,0.358,0.033,0.401}

    0

    0

    Returns: 0.12904666808018028

  35. {0.533,0.278,0.364,0.098,0.47,0.001,0.544,0.001}

    0

    0

    Returns: 0.00317112191323648

  36. {0.22,0.404,0.719,0.259,0.315,0.248,0.359,0.259}

    0

    0

    Returns: 0.12746563858037338

  37. {0.154,0.326,0.602,0.141,0.24,0.112,0.195,0.326}

    0

    0

    Returns: 0.037959851581878826

  38. {0.339,0.484,0.01,0.399,0.377,0.291,0.604,0.219}

    0

    0

    Returns: 0.10945104972766692

  39. {0.053,0.4,0.01,0.397,0.759,0.226,0.316,0.293}

    0

    0

    Returns: 0.0768685878069554

  40. {0.384,0.489,0.049,0.431,0.448,0.252,0.218,0.44}

    0

    0

    Returns: 0.14865457593791112

  41. {0.018,0.302,0.686,0.085,0.913,0.023,0.076,0.43}

    0

    0

    Returns: 0.028070464636325575

  42. {0.511,0.441,0.58,0.004,0.186,0.377,0.262,0.004}

    0

    0

    Returns: 4.2940928E-7

  43. {0.098,0.442,0.297,0.101,0.176,0.246,0.153,0.246}

    0

    0

    Returns: 0.024344156408724716

  44. {0.335,0.379,0.561,0.07,0.812,0.124,0.469,0.379}

    0

    0

    Returns: 0.08996536688037415

  45. {0.025,0.46,0.616,0.152,0.469,0.269,0.85,0.082}

    0

    0

    Returns: 0.026228272892608512

  46. {0.138,0.46,0.61,0.171,0.195,0.323,0.168,0.221}

    0

    0

    Returns: 0.04225203959426001

  47. {0.001,0.403,0.324,0.073,0.432,0.135,0.586,0.251}

    0

    0

    Returns: 0.032211756243620666

  48. {0.533,0.342,0.259,0.054,0.465,0.132,0.535,0.426}

    0

    0

    Returns: 0.06328648667111784

  49. {0.466,0.125,0.74,0.116,0.35,0.492,0.317,0.116}

    0

    0

    Returns: 0.015098964802057115

  50. {0.139,0.37,0.652,0.301,0.466,0.397,0.054,0.37}

    0

    0

    Returns: 0.13983272921820197

  51. {0.334,0.17,0.172,0.062,0.134,0.355,0.203,0.355}

    0

    0

    Returns: 0.06862035404792999

  52. {0.575,0.387,0.762,0.211,0.167,0.419,0.742,0.21}

    0

    0

    Returns: 0.10515915139270166

  53. {0.428,0.121,0.297,0.015,0.299,0.44,0.192,0.101}

    0

    0

    Returns: 0.0019245640232268804

  54. {0.437,0.073,0.925,0.026,0.524,0.472,0.051,0.226}

    0

    0

    Returns: 0.014390633034280655

  55. {0.244,0.027,0.094,0.023,0.725,0.144,0.033,0.345}

    0

    0

    Returns: 0.029793945553919992

  56. {0.12,0.049,0.202,0.282,0.49,0.049,0.03,0.049}

    0

    0

    Returns: 5.270289628740813E-4

  57. {0.141,0.125,0.494,0.42,0.125,0.125,0.363,0.42}

    0

    0

    Returns: 0.00306702775390625

  58. {0.552,0.362,0.288,0.415,0.616,0.362,0.231,0.195}

    0

    0

    Returns: 0.1826916112516655

  59. {0.876,0.048,0.19,0.39,0.102,0.048,0.271,0.122}

    0

    0

    Returns: 0.00165384471969792

  60. {0.402,0.348,0.549,0.374,0.255,0.348,0.366,0.461}

    0

    0

    Returns: 0.16121300099175934

  61. {0.516,0.243,0.417,0.28,0.124,0.28,0.63,0.243}

    0

    0

    Returns: 0.08122719984466728

  62. {0.333,0.096,0.483,0.479,0.198,0.479,0.29,0.479}

    0

    0

    Returns: 0.20956685584049287

  63. {0.143,0.131,0.204,0.479,0.507,0.479,0.419,0.082}

    0

    0

    Returns: 0.07042996282442894

  64. {0.684,0.064,0.298,0.312,0.115,0.312,0.007,0.137}

    0

    0

    Returns: 0.02357175626604909

  65. {0.155,0.083,0.337,0.143,0.766,0.143,0.135,0.458}

    0

    0

    Returns: 0.033081808080040714

  66. {0.165,0.306,0.428,0.397,0.078,0.225,0.381,0.225}

    0

    0

    Returns: 0.04880317707008999

  67. {0.525,0.382,0.18,0.396,0.623,0.096,0.415,0.382}

    0

    0

    Returns: 0.15076250862157328

  68. {0.177,0.402,0.215,0.446,0.105,0.012,0.069,0.446}

    0

    0

    Returns: 0.11527526583859465

  69. {0.274,0.249,0.504,0.418,0.484,0.083,0.474,0.073}

    0

    0

    Returns: 0.038258516600015766

  70. {0.581,0.338,0.443,0.409,0.217,0.034,0.327,0.317}

    0

    0

    Returns: 0.25705032816220863

  71. {0.153,0.192,0.338,0.383,0.119,0.024,0.404,0.294}

    0

    0

    Returns: 0.011574256281845762

  72. {0.27,0.172,0.148,0.221,0.287,0.071,0.111,0.46}

    0

    0

    Returns: 0.012437337255039997

  73. {0.792,0.127,0.287,0.41,0.535,0.283,0.792,0.127}

    0

    0

    Returns: 0.08925935909420737

  74. {0.262,0.013,0.08,0.349,0.173,0.056,0.788,0.056}

    0

    0

    Returns: 3.0738967107072E-4

  75. {0.347,0.027,0.094,0.379,0.221,0.218,0.139,0.379}

    0

    0

    Returns: 0.021383359404029523

  76. {0.132,0.272,0.267,0.48,0.059,0.303,0.073,0.209}

    0

    0

    Returns: 0.032707712261783504

  77. {0.307,0.248,0.388,0.45,0.29,0.318,0.51,0.294}

    0

    0

    Returns: 0.08393147068672727

  78. {0.804,0.056,0.524,0.323,0.724,0.065,0.8,0.187}

    0

    0

    Returns: 0.0027884002088800004

  79. {0.78,0.06,0.077,0.453,0.088,0.216,0.383,0.481}

    0

    0

    Returns: 0.014129547965890561

  80. {0.684,0.068,0.59,0.163,0.363,0.402,0.582,0.068}

    0

    0

    Returns: 0.02005008649770985

  81. {0.407,0.119,0.431,0.299,0.507,0.367,0.685,0.299}

    0

    0

    Returns: 0.23127786276592244

  82. {0.115,0.079,0.052,0.182,0.534,0.208,0.142,0.208}

    0

    0

    Returns: 0.014178837648834559

  83. {0.529,0.087,0.144,0.441,0.228,0.474,0.6,0.057}

    0

    0

    Returns: 0.06377471607787412

  84. {0.403,0.117,0.418,0.179,0.307,0.373,0.129,0.127}

    0

    0

    Returns: 0.016320920120349514

  85. {0.465,0.227,0.33,0.288,0.32,0.4,0.468,0.383}

    0

    0

    Returns: 0.18441875249561604

  86. {0.262,0.077,0.156,0.155,0.14,0.205,0.3,0.462}

    0

    0

    Returns: 0.013483015229999997

  87. {.000001, 0.999, 0.5, 0.49,.000001,.000001, 0.99, 0.0}

    1

    1

    Returns: 0.660275


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: