# Le Monde puzzle [#1036]

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**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.

**A**n arithmetic Le Monde mathematical puzzle to conclude 2017:

Find (a¹,…,a¹³), a permutation of (1,…,13) such that

a¹/a²+a³=a²+a³/a³+a⁴+a⁵=b¹<1

a⁶/a⁶+a⁷=a⁶+a⁷/a⁷+a⁸+a⁹=a⁷+a⁸+a⁹/a⁵+a⁹+a¹⁰=b²<1

a¹¹+a¹²/a¹²+a¹³=a¹²+a¹³/a¹³+a¹⁰=b³<1

**T**he question can be solved by brute force simulation, checking all possible permutations of (1,…,13). But 13! is 6.6 trillion, a wee bit too many cases. Despite the problem being made of only four constraints and hence the target function taking only five possible values, a simulated annealing algorithm returned a solution within a few calls:

*(a¹,…,a¹³)=(6,1,11,3,10,8,4,9,5,12,7,2,13)*

* (b¹,b²,b³)=(1/2,2/3,3/5)*

using the following code:

checka=function(a){ #target to maximise return(1*(a[1]/sum(a[2:3])==sum(a[2:3])/sum(a[3:5]))+ 1*(sum(a[6:7])/sum(a[7:9])==a[6]/sum(a[6:7]))+ 1*(sum(a[7:9])/(a[5]+sum(a[9:10]))==a[6]/sum(a[6:7]))+ 1*(sum(a[11:12])/sum(a[12:13])==sum(a[12:13])/ (a[10]+a[13])))} parm=sample(1:13) cheka=checka(parm) beta=1 for (t in 1:1e6){ qarm=parm idx=sample(1:13,sample(2:12)) qarm[idx]=sample(qarm[idx]) chekb=checka(qarm) if (log(runif(1))

Filed under: Books, Kids, R Tagged: Le Monde, mathematical puzzle, permutation, R, simulated annealingToleave a commentfor the author, please follow the link and comment on their blog:R – Xi'an's Og.

R-bloggers.com offersdaily e-mail updatesabout 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.