What is the average number of tosses required for a coin to give four consecutive heads?
We will solve this as a Markov chain problem. We start with stage 0. At stage 0, two possibilities exist when flipping a coin – H or T. H is counted as one in the right direction, whereas T means you are back to stage 0. From an H, the next flip can lead to HH or 0 with equal probabilities. So, the transition matrix is:

Q <- matrix(c(0.5, 0.5, 0.0, 0.0,
0.5, 0.0, 0.5, 0.0,
0.5, 0.0, 0.0, 0.5,
0.5, 0.0, 0.0, 0.0), nrow = 4)
I <- matrix(c(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1), nrow = 4)
I_Q <- I - Q
I_Q_INV <- solve(I_Q)
NN <- c(1, 1, 1, 1)
NN%*%I_Q_INV
30 28 24 16
It takes average 30 moves from 0 to HHHH.