<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/riddles-on-a-line-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://xianblog.wordpress.com/2018/09/11/riddles-on-a-line-2/"> R – Xi'an's Og</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><strong><a rel="nofollow" href="https://xianblog.files.wordpress.com/2018/08/whalin75.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2018/08/whalin75.jpg?w=450&amp;h=338&amp;fit=450%2C338&amp;resize=450%2C338" data-orig-size="1920,1440" data-medium-file="https://xianblog.files.wordpress.com/2018/08/whalin75.jpg?w=450&amp;h=338&amp;fit=450%2C338&amp;resize=450%2C338?w=300" data-attachment-id="36823" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2018/08/whalin75.jpg?w=450&h=338&fit=450%2C338&resize=450%2C338" data-permalink="https://xianblog.wordpress.com/2018/08/22/riddles-on-a-line/olympus-digital-camera-499/" data-large-file="https://xianblog.files.wordpress.com/2018/08/whalin75.jpg?w=450&amp;h=338&amp;fit=450%2C338&amp;resize=450%2C338?w=450" alt="" data-image-title="" title="Tofino inlet, B.C., 6 Aug, 2018" sizes="(max-width: 450px) 100vw, 450px" width="450" data-comments-opened="1" class="wp-image-36823" data-recalc-dims="1" height="338"></a>A</strong> second <a rel="nofollow" href="https://fivethirtyeight.com/features/how-many-hoops-will-kids-jump-through-to-play-rock-paper-scissors/" target="_blank">Riddle(r)</a>, with a puzzle related with the integer set Ð={,12,3,…,N}, in that it summarises as</p>
<blockquote>
<p><em>Given a random walk on Ð, starting at the middle N/2, with both end states being absorbing states, and a uniform random move left or right of the current value to the (integer) middle of the corresponding (left or right) integer interval, what is the average time to one absorbing state as a function of N?</em></p>
</blockquote>
<p>Once the Markov transition matrix M associated with this random walk is defined, the probability of reaching an absorbing state in t steps can be derived from the successive powers of M by looking at the difference between the probabilities to be (already) absorbed at both t-1 and t steps. From which the average can be derived.</p>
<pre>avexit &lt;- function(N=100){
 #transition matrix M for the walk
 #1 and N+2 are trapping states
 tranz=matrix(0,N+2,N+2)
 tranz[1,1]=tranz[N+2,N+2]=1
 for (i in 2:(N+1))
  tranz[i,i+max(trunc((N+1-i)/2),1)]=tranz[i,i-max(trunc((i-2)/2),1)]=1/2
 #probabilities of absorption
 prowin=proloz=as.vector(0)
 init=rep(0,N+2)
 init[trunc((N+1)/2)]=1 #first position
 curt=init
 while(1-prowin[length(prowin)]-proloz[length(prowin)]>1e-10){
  curt=curt%*%tranz
  prowin=c(prowin,curt[1])
  proloz=c(proloz,curt[N+2])}
 #probability of new arrival in trapping state
 probz=diff(prowin+proloz)
 return(sum((2:length(proloz))*probz))}
</pre>
<p>leading to an almost linear connection between N and expected trapping time.</p>
<p><a rel="nofollow" href="https://xianblog.files.wordpress.com/2018/08/randawk.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2018/08/randawk.jpg" data-orig-size="480,480" data-medium-file="https://xianblog.files.wordpress.com/2018/08/randawk.jpg?w=300" data-attachment-id="36874" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2018/08/randawk.jpg?w=450&h=450&fit=450%2C450&resize=450%2C450" data-permalink="https://xianblog.wordpress.com/2018/09/11/riddles-on-a-line-2/randawk/" data-large-file="https://xianblog.files.wordpress.com/2018/08/randawk.jpg?w=450&amp;h=450&amp;fit=450%2C450&amp;resize=450%2C450" alt="" data-image-title="randawk" sizes="(max-width: 450px) 100vw, 450px" width="450" data-comments-opened="1" class="wp-image-36874" data-recalc-dims="1" height="450"></a></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://xianblog.wordpress.com/2018/09/11/riddles-on-a-line-2/"> R – Xi'an's Og</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/gggDSgr3P8w" height="1"></a></div>