Statistics

Problem Statement for "TheDiceGame"

Problem Statement

Little John has one standard die with numbers one to six on its sides. Each time he throws the die, he gets as many candies from his mom as the number on the top of the die. John’s goal is to collect at least candies candies. Then he will eat them all and became a little fat boy.

Return the expected number of throws needed for John to achieve his goal.

Definition

Class:
TheDiceGame
Method:
expectedThrows
Parameters:
int
Returns:
double
Method signature:
double expectedThrows(int candies)
(be sure your method is public)

Notes

  • The returned value must be accurate to within a relative or absolute value of 1E-9.

Constraints

  • candies will be between 1 and 1000000, inclusive.

Examples

  1. 1

    Returns: 1.0

    John needs only one throw to get at least one candy.

  2. 2

    Returns: 1.1666666666666667

    After the first throw, there is a probability of 1/6 that John will need an additional throw.

  3. 7

    Returns: 2.5216263717421126

  4. 47

    Returns: 13.90476189046144

  5. 9

    Returns: 3.0433247837600974

  6. 6

    Returns: 2.1613940329218106

  7. 8

    Returns: 2.7752307670324643

  8. 3

    Returns: 1.3611111111111112

  9. 4

    Returns: 1.587962962962963

  10. 5

    Returns: 1.8526234567901234

  11. 17

    Returns: 5.33319373864191

  12. 20

    Returns: 6.190195198987439

  13. 36

    Returns: 10.761904997432147

  14. 34

    Returns: 10.190480976827903

  15. 18

    Returns: 5.619895663375334

  16. 35

    Returns: 10.476194803681265

  17. 37

    Returns: 11.0476167312735

  18. 21

    Returns: 6.475816279139172

  19. 30

    Returns: 9.047634594384022

  20. 22

    Returns: 6.761784262898289

  21. 97

    Returns: 28.190476190476154

  22. 50

    Returns: 14.761904780325601

  23. 56

    Returns: 16.476190482101313

  24. 74

    Returns: 21.619047619049557

  25. 68

    Returns: 19.904761904864905

  26. 75

    Returns: 21.904761904746998

  27. 87

    Returns: 25.333333333333048

  28. 51

    Returns: 15.047619080389286

  29. 90

    Returns: 26.190476190476236

  30. 72

    Returns: 21.047619047648613

  31. 1147

    Returns: 328.1904761904732

  32. 1000

    Returns: 286.19047619047393

  33. 1356

    Returns: 387.9047619047577

  34. 1124

    Returns: 321.61904761904475

  35. 1368

    Returns: 391.3333333333291

  36. 1225

    Returns: 350.47619047618707

  37. 1387

    Returns: 396.7619047619004

  38. 1851

    Returns: 529.3333333333255

  39. 1290

    Returns: 369.0476190476153

  40. 1572

    Returns: 449.619047619042

  41. 157147

    Returns: 44899.619047563094

  42. 151000

    Returns: 43143.33333328167

  43. 113356

    Returns: 32387.90476187565

  44. 171124

    Returns: 48893.04761898127

  45. 198368

    Returns: 56677.04761895846

  46. 167225

    Returns: 47779.04761898426

  47. 149387

    Returns: 42682.47619042562

  48. 190851

    Returns: 54529.333333250805

  49. 166290

    Returns: 47511.90476184211

  50. 139572

    Returns: 39878.19047614634

  51. 757148

    Returns: 216328.47618917728

  52. 851001

    Returns: 243143.61904597818

  53. 413357

    Returns: 118102.47619008906

  54. 971125

    Returns: 277464.7619026251

  55. 598369

    Returns: 170963.04761823636

  56. 567226

    Returns: 162065.0476183186

  57. 749388

    Returns: 214111.33333206092

  58. 890852

    Returns: 254529.6190458209

  59. 766291

    Returns: 218940.76190343144

  60. 239573

    Returns: 68449.90476177471

  61. 957147

    Returns: 273471.0476169719

  62. 951000

    Returns: 271714.76190271275

  63. 913356

    Returns: 260959.3333314432

  64. 971124

    Returns: 277464.4761883394

  65. 998368

    Returns: 285248.4761882178

  66. 967225

    Returns: 276350.4761883565

  67. 949387

    Returns: 271253.9047598626

  68. 990851

    Returns: 283100.76190253743

  69. 966290

    Returns: 276083.33333121776

  70. 939572

    Returns: 268449.61904561886

  71. 999996

    Returns: 285713.6190453533

  72. 999999

    Returns: 285714.4761882104

  73. 999992

    Returns: 285712.4761882105

  74. 999996

    Returns: 285713.6190453533

  75. 999990

    Returns: 285711.90475963906

  76. 999999

    Returns: 285714.4761882104

  77. 1000000

    Returns: 285714.76190249616

  78. 999998

    Returns: 285714.19047392474

  79. 2005

    Returns: 573.3333333333243

  80. 101

    Returns: 29.33333333333331


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: