## Riddle of the lanes

**An** express riddle from the Riddler about reopening pools, where lanes are allowed provided there is no swimmer in the lane or in any of the adjacent lanes. If swimmers pick their lane at random (while they can), what is the average number of occupied lanes?

If there are n lanes and E(n) is the expected number of swimmers, E(n) satisfies a recurrence relation determined by the location of the first swimmer:

with E(0)=0, E(1)=E(2)=1. The above can be checked with a quick R experiment:

en=0 for(t in 1:T){ la=rep(u<-0,N) while(sum(la)<N){ i=sample(rep((1:N)[!la],2),1) la[max(1,i-1):min(N,i+1)]=1 u=u+1} en=en+u}

July 13, 2020 at 11:13 am

[…] article was first published on R – Xi'an's Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

July 13, 2020 at 5:17 am

[…] by data_admin [This article was first published on R – Xi’an’s Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]