Statistics

Problem Statement for "LuckyFives"

Problem Statement

Some people think five is a lucky number. They roll several dice, and if they get five on strictly more than one fifth of the dice, they believe it will be a lucky day.

Given an int dice, the number of dice rolled, and an int sides, the number of sides on each die, return the probability of the day being lucky. For a die with N sides, the probability of rolling a five is 1/N.

Definition

Class:
LuckyFives
Method:
probability
Parameters:
int, int
Returns:
double
Method signature:
double probability(int dice, int sides)
(be sure your method is public)

Notes

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

Constraints

  • dice will be between 1 and 20, inclusive.
  • sides will be between 5 and 10, inclusive.

Examples

  1. 1

    6

    Returns: 0.16666666666666666

    If you roll one six-sided die, you will get five with a probability of 1/6.

  2. 5

    6

    Returns: 0.19624485596707822

    Here you roll five six-sided dice, and you need at least two fives.

  3. 4

    10

    Returns: 0.3439

  4. 20

    10

    Returns: 0.04317449528446337

  5. 1

    5

    Returns: 0.2

  6. 2

    5

    Returns: 0.36

  7. 3

    5

    Returns: 0.488

  8. 4

    5

    Returns: 0.5904

  9. 5

    5

    Returns: 0.26271999999999995

  10. 6

    5

    Returns: 0.34463999999999995

  11. 7

    5

    Returns: 0.4232832

  12. 8

    5

    Returns: 0.49668351999999993

  13. 9

    5

    Returns: 0.563792384

  14. 10

    5

    Returns: 0.32220047360000004

  15. 11

    5

    Returns: 0.3825984512

  16. 14

    5

    Returns: 0.55194901168128

  17. 15

    5

    Returns: 0.351837895426048

  18. 16

    5

    Returns: 0.401865674489856

  19. 19

    5

    Returns: 0.5449112576542113

  20. 20

    5

    Returns: 0.3703517360973309

  21. 1

    10

    Returns: 0.1

  22. 2

    10

    Returns: 0.19

  23. 5

    10

    Returns: 0.08146

  24. 10

    10

    Returns: 0.0701908264

  25. 20

    10

    Returns: 0.04317449528446337

  26. 18

    10

    Returns: 0.09819684142543736

  27. 7

    7

    Returns: 0.26351386630692025

  28. 7

    8

    Returns: 0.21460819244384766

  29. 3

    9

    Returns: 0.29766803840877915

  30. 18

    9

    Returns: 0.13172836617939196

  31. 12

    6

    Returns: 0.3225738051009248

  32. 15

    6

    Returns: 0.23151921721652627

  33. 15

    7

    Returns: 0.1558916567625231

  34. 15

    8

    Returns: 0.10778457854496537

  35. 15

    9

    Returns: 0.0764692476356838

  36. 15

    10

    Returns: 0.055555630007535994

  37. 20

    10

    Returns: 0.04317449528446337

  38. 10

    8

    Returns: 0.11950215324759483

  39. 1

    5

    Returns: 0.2

  40. 13

    6

    Returns: 0.37192273320615543


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: