**The stupidest thing... » R**, and kindly contributed to R-bloggers)

Matt Maenner asked about the sawtooth pattern in the figure in my last post on Chutes & Ladders.

Damn you, Matt! I thought I was done with this. Don’t feed my obsession.

My response was that if the game ends early, it’s even more likely that it’ll be the kid who went first who won. *But*, my intuition was wrong: exactly the opposite is true. *It is* the advantage to the first player that causes the sawtooth pattern, but that advantage *increases* with the number of rounds rather than decreases.

### Numerical results

While it’s fast and easy to study the Chutes & Ladders game by simulation, if you want to answer questions more precisely, it’s best to switch to more exact results.

Consider a single individual playing the game, and let X_{n} be his/her location at round n. The X_{n} form a *Markov chain*, in that the future (X_{n+1}), given the present (X_{n}), is conditionally independent of the history (X_{1}, …, X_{n-1}).

It’s relatively easy to construct the transition matrix of the chain. (See my R code.) This is a matrix P, with P_{ij} = Pr(X_{n+1} = j | X_{n} = i).

Then the probability that a player has reached state 100 by round n is

(1, 0, …, 0) P^{n} (0, …, 0, 1)’. That’s the cumulative distribution function (cdf) of the number of rounds for a single player to finish the game. Call this q_{n}. You can get the probability distribution by differences, say p_{n} = q_{n} – q_{n-1}.

To calculate the number of rounds to complete a game with k players, you want the minimum of k independent draws from this distribution. The probability that a game with k players is complete by round n is 1 – (1-q_{n})^{k}. And again you can get the probability distributions by differences. Here’s a picture.

### Advantage to the first player

Now, regarding the advantage to the first player: note that the first player wins in exactly n steps if he gets to the finish at n steps and none of the other players are done by n-1 steps. So, with k players, the probability that the first player wins in exactly n steps is p_{n} (1-q_{n-1})^{k-1}.

The chance that the second player wins in exactly n steps is (1-q_{n}) p_{n} (1-q_{n-1)})^{k-2}, with the last term included only if there are k > 2 players.

From this idea, it’s straightforward to calculate the probability that the first player wins given that the game is complete at round n. Here’s a plot of that probability as a function of the number of players, relative to the nominal probability (1/2, 1/3, 1/4).

Note that n=7 is the minimum number of rounds to complete the game. I’d thought that the first player’s advantage went down over time, but the opposite is true.

### No. spins to end the game

Combining these two results (on the number of rounds to complete the game and the probability that player i will win in n rounds), we can get a more precise version of the simulation-based figure in my last post:

As you can see, the sawtooth pattern becomes more pronounced with the number of rounds, but then it gets lost in the downward slope of the distribution on the right side. (Again, see my R code.)

**leave a comment**for the author, please follow the link and comment on their blog:

**The stupidest thing... » R**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...