Statistics

Problem Statement for "DisjointDiceValues"

Problem Statement

Alice rolled A standard six-sided dice. At the same time, Bob rolled another B standard six-sided dice.


Alice wins if at least one of her dice matches one of Bob's dice. Bob wins if that does not happen.

For example, if Alice rolls 1,3,3,6 and Bob rolls 2,3,5,5,5, Alice wins because they both rolled a 3. On the other hand, if Alice rolls 1,3,3,6 and Bob rolls 4,4,4,2,4, Bob wins because all of Alice's dice show numbers different from those on Bob's dice.


Given A and B, what is the probability that Alice wins?

Definition

Class:
DisjointDiceValues
Method:
getProbability
Parameters:
int, int
Returns:
double
Method signature:
double getProbability(int A, int B)
(be sure your method is public)

Notes

  • Return values that differ from the reference solution by at most 1e-9 will be accepted as correct.

Constraints

  • A and B will be positive integers with A + B <= 16.

Examples

  1. 1

    1

    Returns: 0.16666666666666663

    Alice has one die and Bob has one die. With probability 1/6 Alice will roll the same value as Bob and win.

  2. 4

    1

    Returns: 0.5177469135802468

    Alice has four dice while Bob has one. Alice can view this game as her having four chances to roll the number that will come up on Bob's single die. (An interesting historical fact: This example is closely related to a famous problem that was the motivation for Blaise Pascal to invent discrete probability. Empirically this game feels approximately fair, but as we see, Alice's win probability is actually slightly more than 50 percent.)

  3. 1

    4

    Returns: 0.5177469135802468

    The game is actually symmetric: the probability that one of Bob's dice matches Alice's single die is the same as it was when Alice had four dice and Bob just one.

  4. 3

    3

    Returns: 0.7910236625514401

    With three dice each it is already quite likely that at least one of their outcomes will match. The exact probability that Alice wins is 6151/7776.

  5. 1

    15

    Returns: 0.9350945284811255

  6. 15

    1

    Returns: 0.9350945284811255

  7. 8

    8

    Returns: 0.9995852316186237

  8. 7

    9

    Returns: 0.9995453088635047

  9. 10

    6

    Returns: 0.9993990056801695

  10. 5

    11

    Returns: 0.9990361169329797

  11. 12

    4

    Returns: 0.9980957242481756

  12. 3

    13

    Returns: 0.9951950346797287

  13. 14

    2

    Returns: 0.9841643328705736

  14. 9

    5

    Returns: 0.9975680660643998

  15. 7

    8

    Returns: 0.9991587419356731

  16. 2

    2

    Returns: 0.5138888888888888

  17. 2

    1

    Returns: 0.30555555555555547

  18. 3

    7

    Returns: 0.96352092779937

  19. 8

    4

    Returns: 0.9903883867238438

  20. 6

    8

    Returns: 0.9982115265106596

  21. 5

    10

    Returns: 0.9984872186621582

  22. 10

    1

    Returns: 0.8384944171101543


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: