Statistics

Problem Statement for "Monopolies"

Problem Statement

   0  1  2  3  4  5  6  7  8  9 10 
  39                            11
  38                            12
  37                            13
  36                            14
  35                            15
  34                            16
  33                            17
  32                            18
  31                            19
  30 29 28 27 26 25 24 23 22 21 20
In a certain board game, there are 40 numbered squares arranged around the board as shown above. The players alternate turns. On each turn a player rolls 2 six-sided dice and moves forward (clockwise) the sum of the two values. If he lands on square 7, 22, or 36 he draws a card which may direct him to move forward to a specified square or to "go to jail". There are 20 cards, and after a card has been drawn it is replaced and the cards are reshuffled:
  • 2 cards say "go to jail"
  • 1 card says "go to square 11"
  • 1 card says "go to square 24"
  • 1 card says "go to square 29"
  • 1 card says "go to square 39"
  • 14 cards don't cause him to move

If he has not gone to jail and has rolled "doubles" (the 2 dice have the same value) he continues his turn by rolling again and behaving as before. However, if he rolls doubles 3 times on one turn, he does not move the amount shown on the third roll -- instead he "goes to jail". The player's turn ends after he moves on a roll that was not doubles, or when he goes to jail.

One additional rule is that if a player lands on square 30, his turn ends after that move and he goes to jail.

We want to analyze the beginning of a 2 player game. Both players start on square 0. We will pretend that a player is removed from the game when he goes to jail or when he gets past square 39 (possibly by being directed to move by a card). So if a card directs a player to a lower numbered square, the player is removed from the game before landing on that square. If a card directs a player to a higher numbered square, he has landed on both the square where he drew the card and on the square he was directed to.

For a particular square we want to know the probability that the 2nd player will land on it without having the first player land on it earlier. Create a class Monopolies that contains a method probability the is given square and that returns the desired probability.

Definition

Class:
Monopolies
Method:
probability
Parameters:
int
Returns:
double
Method signature:
double probability(int square)
(be sure your method is public)

Notes

  • A return value with either an absolute or relative error of less than 1.0E-9 is considered correct.

Constraints

  • square will be between 1 and 39, inclusive.

Examples

  1. 1

    Returns: 0.0

    No player can land on square 1 on his first time around the board, since the smallest possible roll causes a player to move 2 squares forward.

  2. 22

    Returns: 0.12122739832411301

  3. 30

    Returns: 0.11905533142891316

  4. 2

    Returns: 0.02700617283950617

  5. 3

    Returns: 0.05246913580246913

  6. 4

    Returns: 0.07703129762993446

  7. 5

    Returns: 0.1013303040695016

  8. 6

    Returns: 0.12576922344154856

  9. 7

    Returns: 0.15088612883709107

  10. 8

    Returns: 0.14160983526099324

  11. 9

    Returns: 0.13433119750204223

  12. 10

    Returns: 0.12849058025937032

  13. 11

    Returns: 0.12997543693093566

  14. 12

    Returns: 0.1153706558754526

  15. 13

    Returns: 0.1055704182700689

  16. 14

    Returns: 0.11531429009467811

  17. 15

    Returns: 0.12264982036529136

  18. 16

    Returns: 0.12556340986511677

  19. 17

    Returns: 0.12668859198231022

  20. 18

    Returns: 0.12534381013999316

  21. 19

    Returns: 0.1238262793463571

  22. 20

    Returns: 0.12185016220185278

  23. 21

    Returns: 0.12146889135612082

  24. 23

    Returns: 0.12232086565758749

  25. 24

    Returns: 0.13480148842285747

  26. 25

    Returns: 0.12177071374458667

  27. 26

    Returns: 0.12113851223949007

  28. 27

    Returns: 0.12053932414517979

  29. 28

    Returns: 0.1192242873555245

  30. 29

    Returns: 0.131666737155619

  31. 31

    Returns: 0.12038599085890288

  32. 32

    Returns: 0.11795227276092908

  33. 33

    Returns: 0.11543841147751183

  34. 34

    Returns: 0.11301763081954233

  35. 35

    Returns: 0.11023636159206301

  36. 36

    Returns: 0.10663353172704458

  37. 37

    Returns: 0.10184209378335683

  38. 38

    Returns: 0.10285677033608957

  39. 39

    Returns: 0.12165542859662269

  40. 36

    Returns: 0.10663353172704458


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: