# Why is it more likely to be in the lead 0 or 40 times, rather than 20 in this example?

(https://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/amsbook.mac.pdf) (this question comes from here page 6)

figure1.4

The intuition that 20 should be the most likely result is probably related to the Gambler's fallacy.

It might feel intuitive, or more fair, that after Peter wins the first toss (say) the odds should turn to Paul's favor to even out the score. In reality, once one player has a lead, the expectation is that they keep the lead - the fact that Peter won more often in the past is irrelevant.

The fundamental result is called the Arcsine Law, for which @user462110 gives a nice intuitive justification (+1). Feller's famous probability book has a proof, which this page discusses in detail.

Roughly stated the Arcsine Law says that, for sufficiently large number $n$ of plays, the proportion of the time that Peter is ahead is approximately $\mathsf{Beta}(.5,.5).$ The name 'Arcsine Law' arises because the CDF of this beta distribution contains an arcsine function.

Below is a simulation for $n = 200,$ which is large enough for a histogram of the proportion of time Peter is ahead to give a very nice fit to the PDF (red curve below) of $\mathsf{Beta}(.5,.5).$ Certainly, your claim is true for $n = 40$ (the low bin of the histogram is centered at 0.5), but $n = 200$ makes a nicer graph.

The R program below simulates a million 200-toss games. Each game begins with a vector ht of 200 coin tosses. The vector x finds Peter's cumulative 'fortune' after each toss, and the lagged vector xp shows his fortune at the previous toss in order to implement your convention about being ahead or behind if a $0$ fortune occurs. Finally, the quantity ahead shows the proportion of tosses at which Peter was ahead in the $i$th game.

m = 10^6;  ahead= numeric(m);  n = 200
for(i in 1:m) {
ht = sample(c(-1,1), n, repl=T)
x = cumsum(ht); xp = c(0,x[1:(n-1)])
ahead[i] = mean(sign(x+xp)>0) }