[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 here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Here is the cRude code I later wrote to check whether or not this was working:
p=1+t%%N #starting item position h=v=s=m=1 #h=door, v=attempt number, s=direction, m=repeat number while(h-p){ p=ifelse(p==1,2, #no choice ifelse(p==N,N-1, #no choice ifelse(p==h-1,p-1, #avoid door ifelse(p==h+1,p+1, #avoid door p+sample(c(-1,1),1))))) #random m=m+1 if(m>2){ h=h+s;m=1 if(h>N){ h=N-1;s=-1} if(!h){ s=1;h=2} } v=v+1
and the outcome for N=100 was a maximum equal to 198. The optimal strategy leads to 196 as repeating the extreme doors is not useful.
To leave a comment for the author, please follow the link and comment on their blog: R – Xi'an's Og.
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.