Statistics

Problem Statement for "TheTicketsDivOne"

Problem Statement

John has two tickets for the basketball game - one for himself and one for a friend. However, he has n friends who want to go with him. He decides to use the following strategy to choose one of them. First, he tells his friends to form a straight single file line. Then, he repeats the following step until he has made a choice. If there is only one friend in line, John chooses him. Otherwise, he throws a standard six-sided die. If the number 4 is on top, he chooses the friend who is currently first in line. Otherwise, if the number is odd, the first friend in line must move to the end of the line, and if the number is even, the first friend in line must leave the line and go home.

You are given an int m, the 1-based index of a friend in the initial line. The index of the first friend is 1, and the index of the last friend is n. Return the probability that the m-th friend in the initial line is ultimately chosen by John.

Definition

Class:
TheTicketsDivOne
Method:
find
Parameters:
int, int
Returns:
double
Method signature:
double find(int n, int m)
(be sure your method is public)

Notes

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

Constraints

  • n will be between 1 and 1,000, inclusive.
  • m will be between 1 and n, inclusive.

Examples

  1. 2

    1

    Returns: 0.4444444444444444

    John will throw the dice and thus six outcomes are possible: 1: The first friend will go to the end of the line and John will repeat the action. 2: The first friend will go home and John will choose the second friend. 3: The first friend will go to the end of the line and John will repeat the action. 4: John will choose the first friend. 5: The first friend will go to the end of the line and John will repeat the action. 6: The first friend will go home and John will choose the second friend.

  2. 2

    2

    Returns: 0.5555555555555556

  3. 1

    1

    Returns: 1.0

    Only one friend here.

  4. 3

    2

    Returns: 0.31746031746031744

  5. 25

    1

    Returns: 0.16776527430800667

  6. 7

    1

    Returns: 0.21272477008341567

  7. 40

    26

    Returns: 0.0017521393226481148

  8. 17

    3

    Returns: 0.11993258942241557

  9. 43

    27

    Returns: 0.0014585205711715305

  10. 38

    27

    Returns: 0.0014625153332662843

  11. 23

    10

    Returns: 0.03294600045355396

  12. 22

    3

    Returns: 0.1173214640737295

  13. 18

    7

    Returns: 0.058145594919708644

  14. 37

    4

    Returns: 0.09653754521315697

  15. 18

    7

    Returns: 0.058145594919708644

  16. 12

    4

    Returns: 0.10736589253163475

  17. 37

    12

    Returns: 0.022469018416812463

  18. 7

    1

    Returns: 0.21272477008341567

  19. 8

    3

    Returns: 0.146740717545711

  20. 8

    5

    Returns: 0.107905269308481

  21. 47

    42

    Returns: 9.475790347815949E-5

  22. 44

    29

    Returns: 0.001012810488300904

  23. 44

    6

    Returns: 0.06699911122616958

  24. 47

    32

    Returns: 5.85838661241397E-4

  25. 46

    23

    Returns: 0.003021262465457692

  26. 44

    15

    Returns: 0.01298868651151011

  27. 44

    41

    Returns: 1.139030212404029E-4

  28. 46

    37

    Returns: 2.35666564043745E-4

  29. 46

    11

    Returns: 0.026925601755560444

  30. 45

    31

    Returns: 7.033061884509057E-4

  31. 25

    1

    Returns: 0.16776527430800667

  32. 7

    1

    Returns: 0.21272477008341567

  33. 40

    1

    Returns: 0.16673530169869788

  34. 17

    1

    Returns: 0.171763066351931

  35. 43

    1

    Returns: 0.16670628940724788

  36. 25

    25

    Returns: 0.002197215282679989

  37. 7

    7

    Returns: 0.092116206833498

  38. 40

    40

    Returns: 1.3727006406245328E-4

  39. 17

    17

    Returns: 0.010192799370528687

  40. 43

    43

    Returns: 7.924548116240987E-5

  41. 47

    42

    Returns: 9.475790347815949E-5

  42. 47

    19

    Returns: 0.006263051514682197

  43. 47

    45

    Returns: 5.4877050657080916E-5

  44. 47

    32

    Returns: 5.85838661241397E-4

  45. 47

    1

    Returns: 0.16668573258953942

  46. 47

    47

    Returns: 3.8131845745485545E-5

  47. 47

    23

    Returns: 0.0030208806165636496

  48. 1000

    1

    Returns: 0.16666666666666666

  49. 1000

    125

    Returns: 2.5314784793751827E-11

  50. 1000

    226

    Returns: 2.5472313367414E-19

  51. 1000

    852

    Returns: 3.0E-32

  52. 1000

    573

    Returns: 3.0E-32

  53. 1000

    7

    Returns: 0.05581632944673068

  54. 1000

    437

    Returns: 3.0E-32

  55. 1000

    523

    Returns: 3.0E-32

  56. 1000

    529

    Returns: 3.0E-32

  57. 1000

    291

    Returns: 1.81671747E-24

  58. 1000

    227

    Returns: 2.1226927806178E-19

  59. 1000

    252

    Returns: 2.22513308733E-21

  60. 1000

    269

    Returns: 1.0029396683E-22

  61. 951

    475

    Returns: 3.0E-32

  62. 966

    483

    Returns: 3.0E-32

  63. 992

    496

    Returns: 3.0E-32

  64. 981

    490

    Returns: 3.0E-32

  65. 969

    484

    Returns: 3.0E-32

  66. 996

    3

    Returns: 0.11574074074074074

  67. 992

    1

    Returns: 0.16666666666666666

  68. 990

    1

    Returns: 0.16666666666666666

  69. 997

    1

    Returns: 0.16666666666666666

  70. 1000

    3

    Returns: 0.11574074074074074

  71. 1000

    1

    Returns: 0.16666666666666666

  72. 1000

    1000

    Returns: 3.0E-32

  73. 1000

    500

    Returns: 3.0E-32

  74. 1000

    4

    Returns: 0.09645061728395062

  75. 110

    110

    Returns: 3.900274442572262E-10

  76. 128

    122

    Returns: 4.374396941772629E-11

  77. 52

    50

    Returns: 2.2021905767741966E-5

  78. 163

    145

    Returns: 6.603121991488001E-13

  79. 173

    68

    Returns: 8.254775460163392E-7

  80. 136

    104

    Returns: 1.16460974290397E-9

  81. 83

    61

    Returns: 2.9578835127451844E-6

  82. 94

    89

    Returns: 1.794350668344125E-8

  83. 103

    92

    Returns: 1.0383825105978649E-8

  84. 101

    93

    Returns: 8.653209789287519E-9

  85. 98

    91

    Returns: 1.2460665231186242E-8

  86. 105

    93

    Returns: 8.653177594869053E-9

  87. 92

    87

    Returns: 2.583876453475784E-8

  88. 102

    83

    Returns: 5.3578157834141396E-8

  89. 97

    87

    Returns: 2.5838402947961E-8

  90. 90

    85

    Returns: 3.720802529862536E-8

  91. 91

    88

    Returns: 2.15324530526375E-8

  92. 101

    100

    Returns: 2.414964438734903E-9

  93. 101

    98

    Returns: 3.4775426758278295E-9

  94. 102

    98

    Returns: 3.477536551997076E-9

  95. 98

    98

    Returns: 3.4775694400722464E-9

  96. 102

    102

    Returns: 1.6770580593590213E-9

  97. 100

    100

    Returns: 2.4149703940927286E-9

  98. 1000

    100

    Returns: 2.4149346944827333E-9

  99. 101

    101

    Returns: 2.0124723507316943E-9

  100. 104

    104

    Returns: 1.1646210012967942E-9

  101. 107

    107

    Returns: 6.739687149675048E-10

  102. 997

    779

    Returns: 3.0E-32

  103. 1000

    999

    Returns: 3.0E-32

  104. 1000

    391

    Returns: 3.0E-32

  105. 51

    51

    Returns: 1.836292277544459E-5

  106. 10

    5

    Returns: 0.09650729524561763

  107. 999

    42

    Returns: 9.44969217773099E-5

  108. 990

    500

    Returns: 3.0E-32

  109. 1000

    10

    Returns: 0.03230111657796914

  110. 997

    995

    Returns: 3.0E-32

  111. 1000

    389

    Returns: 3.0E-32

  112. 50

    47

    Returns: 3.806515119122412E-5

  113. 1000

    13

    Returns: 0.01869277579743585

  114. 90

    90

    Returns: 1.4953273949768097E-8

  115. 1000

    103

    Returns: 1.39753165189973E-9


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: