Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
w=0*(1:N)#frequency of most likely last for(t in 1:1e6){ o=0*w#probabilities of being last for(v in 1:1e6)#sample order of visits o[i]=o[i<-1+unique(cumsum(sample(c(-1,1),300,rep=T))%%N)[N]]+1 w[j]=w[j<-order(o)[N]]+1}
However, upon (jogging) reflection, the double loop is a waste of energy and
o=0*(1:N) for(v in 1:1e8) o[i]=o[i<-1+unique(cumsum(sample(c(-1,1),500,rep=T))%%N)[N]]+1
should be enough to check that all n positions but both neighbours have the same probability of being last visited. Removing the remaining loop should be feasible by considering all subchains starting at one of the 0’s, since this is a renewal state, but I cannot fathom how to code it succinctly. A more detailed coverage of the original problem (that is, omitting the starting point) was published the Monday after publication of the riddle on R bloggers, following a blog post by David Robinson on Variance Explained.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.