What is the expected length of a streak of heads or tails when flipping a coin? What distribution is this?
I'm pretty sure the answer is 2. But I don't know what distributions it is..
I did the following R code:
l=10000
longest.stk = avg.stk = numeric(l)
for(i in 1:l){
x=sample(0:1, 1000, repl=T)
r = rle(x)
longest.stk[i] = max(r$lengths)
avg.stk[i] = mean(r$lengths) }
mean(longest.stk)
[1] 10.3001
mean(avg.stk)
[1] 2.000825