Problem 59132. Snakes and Ladders: Average Number of Turns
In this problem, you will play a single-player variant of the classic game Snakes and Ladders. The rules are as follows:
- The player begins on the "zero" square. (There is no zero square, so practically off the board, entering it on the first turn.)
- Each turn is played by throwing a standard 6-sided die and moving along the squares, in order.
- If the square at which the player arrives after traveling the number of squares indicated by the die is the foot of a ladder or the mouth of a snake, the player immediately moves the square at the top of the ladder or at the tail of the snake, respectively.
- If the die shows a number greater then the number of steps required for the player to reach the final square (overshoot), the player stays in the current square and the turn is wasted.
- The game ends when the player arrives at the final square.
You are given a board, represented by an integer vector. Some vector elements will consist of their own index in the vector, while others will hold the index of a different element in the vector. The latter represent either a snake or a ladder, where snakes will consist of numbers lower than their indeces and ladders higher. You may assume the following:
- Snakes and ladders will not connect in series, i.e. the mouth of a snake or the foor of a ladder will not coincide with the tail of a snake or the top of a ladder.
- There will not be a ladder leading to the final position.
Return n, the expected number of turns for a player to reach the final square.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers4
Suggested Problems
-
166 Solvers
-
1089 Solvers
-
366 Solvers
-
757 Solvers
-
189 Solvers
More from this Author45
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!