<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/the-riddle-of-the-stands/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://xianblog.wordpress.com/2018/05/11/the-riddle-of-the-stands/"> 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://i2.wp.com/imgs.xkcd.com/blag/urinals/urinals7.png?zoom=2" target="_blank"><img alt="" width="450" src="https://i2.wp.com/imgs.xkcd.com/blag/urinals/urinals7.png?zoom=2" height="267"></a>T</strong>he simple <a rel="nofollow" href="https://fivethirtyeight.com/features/how-fast-can-you-type-a-million-letters/" target="_blank">riddle</a> of last week on <a rel="nofollow" href="https://fivethirtyeight.com/features/how-fast-can-you-type-a-million-letters/" target="_blank">The Riddler</a>, about the minimum number of urinals needed for n men to pee if the occupation rule is to stay as far as possible from anyone there and never to stand next to another man,  is quickly solved by an R code:</p>
<pre>ocupee=function(M){
 ok=rep(0,M)
 ok[1]=ok[M]=1
 ok[trunc((1+M/2))]=1
 while (max(diff((1:M)[ok!=0])>2)){
  i=order(-diff((1:M)[ok!=0]))[1]
  ok[(1:M)[ok!=0][i]+trunc((diff((1:M)[ok!=0])[i]/2))]=1
  }
 return(sum(ok>0))
 }
</pre>
<p>with maximal occupation illustrated by the graph below:</p>
<p><a rel="nofollow" href="https://xianblog.files.wordpress.com/2018/05/riddler0429.jpg" target="_blank"><img data-orig-file="https://xianblog.files.wordpress.com/2018/05/riddler0429.jpg" data-orig-size="480,480" data-medium-file="https://xianblog.files.wordpress.com/2018/05/riddler0429.jpg?w=300" data-attachment-id="36069" data-image-meta="{" data-image-description="" src="https://xianblog.files.wordpress.com/2018/05/riddler0429.jpg?w=334&h=334&fit=334%2C334&resize=334%2C334" data-permalink="https://xianblog.wordpress.com/2018/05/11/the-riddle-of-the-stands/riddler0429/" data-large-file="https://xianblog.files.wordpress.com/2018/05/riddler0429.jpg?w=334&amp;h=334&amp;fit=334%2C334&amp;resize=334%2C334" alt="" data-image-title="riddler0429" sizes="(max-width: 334px) 100vw, 334px" width="334" data-comments-opened="1" class="wp-image-36069" data-recalc-dims="1" height="334"></a></p>
<p>Meaning that the efficiency of the positioning scheme is not optimal when following the sequential positioning, requiring $latexN+2^{\lceil log_2(N-1) \rceil}$ urinals. Rather than one out of two, requiring 2N-1 urinals. What is most funny in this simple exercise is the connection exposed in the Riddler with an <a rel="nofollow" href="https://blog.xkcd.com/2009/09/02/urinal-protocol-vulnerability/" target="_blank">Xkcd blag</a> written a few years go about the topic.</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/05/11/the-riddle-of-the-stands/"> 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/CPy3CllE7sI" height="1"></a></div>