<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/le-monde-puzzle-1066-3/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://xianblog.wordpress.com/2018/10/03/le-monde-puzzle-1066-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/2015/10/lemondapari.jpeg" target="_blank"><img src="https://xianblog.files.wordpress.com/2015/10/lemondapari.jpeg?w=450&h=299&fit=456%2C456" data-recalc-dims="1"></a>A </strong>purely (?) algorithmic <a rel="nofollow" href="https://xianblog.wordpress.com/2011/09/03/le-monde-puzzle-website/" title="Le Monde puzzle [website]" target="_blank">Le Monde mathematical puzzle</a></p>
<blockquote>
<p><em>For the table below, what is the minimal number of steps required to reach equal entries when each step consists in adding ones to three entries sitting in a </em>L<em>, such as (7,11,12) or (5,6,10)? Same question for the inner table of four in yellow.<a rel="nofollow" href="http://www.affairedelogique.com/espace_probleme.php?corps=probleme&num=1069" target="_blank"><img width="160" src="https://i2.wp.com/www.affairedelogique.com/backoffice/img/fck/affairedelogique/L2B.jpg" height="160"></a><br>
</em></p>
</blockquote>
<p>For the inner table, this is straightforward as there are four possible L’s, three equations like 6+n⁶=7+n⁷,  and two degrees of freedom leading to a unique entry of N=13 (impossible!)  or 16 (feasible). Hence adding 10 L’s. For the entire table, summing up all entries after completion leads to 16N, which is also equal to 1+3+3+…+16+M, where M is the number of added L’s, itself equal to 138+3O, if O denotes the number of ones added. Hence M can only take the values 18, 21, … It took me quite a while to R code an approach to complete the table into 16 18’s, as my versions of simulated annealing did not seem to converge. In the end, I used a simplified version where the table was completed by multinomial draws, like a M(17;3⁻¹,3⁻¹,3⁻¹) for the upper left corner, corresponding to random draws of one of the 36 available L’s, which should be used 50 times in total, and then augmented or reduced of one L depending on the value at a randomly selected entry. Leading to the result</p>
<pre>> aneal(grid=c(1,3,3:13,15,15,16),maxT=1e5)
 [1] 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18
</pre>
<p><span></span>The R code is quite simple-minded if a wee bit long, using a preliminary definition of the 36 L’s as a 26×3 matrix named allels:</p>
<pre>aneal=function(gri,horz=1e3){
  numbels=rep(0,36)
  sumz=rep(0,16)
  while (sum(numbels)&lt;50){ #50 L's used in toto
    i=sample(1:16,1)
    if (sum(numbels[apply(i==allels,1,max)==1])&lt;18-gri[i]){
      rez=18-gri[i]-sum(numbels[apply(i==allels,1,max)==1])#leftover
      indz=(1:36)[apply(i==allels,1,max)==1]
      indz=indz[numbels[indz]==0]#empty L's
      indz=sample(rep(indz,2),rez,rep=TRUE)
      for (j in indz) numbels[j]=numbels[j]+1
    }}
  t=1
  while (t&lt;horz){ i=sample(1:16,1) 
    indz=(1:36)[apply(i==allels,1,max)==1] 
    sumz=sum(numbels[indz])+gri[i] 
    if (sumz>18){#remove one L
      subz=indz[numbels[indz]>0]#used local L's
      j=sample(rep(subz,2),1)
      numbels[j]=numbels[j]-1}
    if (sumz&lt;18){#add one local L
      j=sample(rep(indz,2),1)
      numbels[j]=numbels[j]+1}
    for (i in 1:16)#check constraints
      sumz[i]=sum(numbels[apply(i==allels,1,max)==1])+gri[i]
    if ((min(sumz)==18)&amp;(max(sumz)==18)) break()
  t=t+1}
  print(sumz)}
</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/10/03/le-monde-puzzle-1066-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 width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/VZQhAk5VGO4" height="1"></a></div>