<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/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://xianblog.wordpress.com/2018/08/22/riddles-on-a-line/"> 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>I</strong>n the <a rel="nofollow" href="https://fivethirtyeight.com/features/step-1-game-theory-step-2-step-3-profit/" target="_blank">Riddler of August 18</a>, two riddles connected with the integer set Ã�={2,3,…,10}:</p>
<ol>
<li><em>Given a permutation of Ã�, what is the probability that the most likely variation (up or down) occurs at each term?</em></li>
<li><em>Given three players choosing three different integers in Ã� sequentially, and rewards in Ã� allocated to the closest of the three players (with splits in case of equal distance), what is the reward for each given an optimal strategy?</em></li>
</ol>
<p>For the first question, a simple code returns 0.17…</p>
<pre>winofail&lt;-function(permz){ 
  if (length(permz)>1){
    lenoperm=length(permz[-1])/2
    win=(permz[1]&lt;permz[2])*(sum(permz[-1]>permz[1])>lenoperm)+
     (permz[1]>permz[2])*(sum(permz[-1]&lt;permz[1])>lenoperm)+
      (runif(1)&lt;.5)*(sum(permz[-1]>permz[1])==lenoperm)
    win=win&amp;&amp;winofail(permz[-1])
  }else win=TRUE
  return(win)}
</pre>
<p>and for the second question, a quick recursion produces 17, 18, 17 as the rewards</p>
<pre>gainz&lt;-function(seqz){
  difz=t(abs(outer(2:10,seqz,&quot;-&quot;)))
  cloz=apply(difz,2,rank)
  return(apply((2:10)*((cloz==1)+.5*(cloz==1.5),1,sum))}

timeline&lt;-function(prev){ 
  if (length(prev)==0){ 
   sol=timeline(10);bez=gainz(sol)[1] 
   for (i in 2:9){ 
    bol=timeline(i);comp=gainz(bol)[1] 
    if (comp>bez){
        bez=comp;sol=bol}}}
  if (length(prev)==1){
    bez=-10
    for (i in (2:10)[-(prev-1)]){
      bol=timeline(c(prev,i))
      comp=gainz(bol)[2]
      if (comp>bez){
        bez=comp;sol=bol}}}
  if (length(prev)==2){
    bez=-10
    for (i in (2:10)[-(prev-1)]){
      bol=c(prev,i)
      comp=gainz(bol)[3]
      if (comp>bez){
        bez=comp;sol=bol}}}
  return(sol)}
</pre>
	<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/08/22/riddles-on-a-line/"> 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/zlnJiArVRp8" height="1"></a></div>