# Le Monde puzzle [#4]

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

**Xi'an's Og » R**, 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** fairly simple puzzle in this weekend ** Le Monde** magazine:

*given five points on a line such that their pairwise distances are 1,2,4,…,14,18,20, find the respective positions of the five points over the line and deduce the missing distances*. Without loss of generality, we can set the first point at 0 and the fifth point at 20. The three remaining points are in between 1 and 19, but again without loss of generality we can choose the fourth point to be at 18. (Else the second point would be at 2.) Finding the three remaining points can be done by the R code

i=1 while (i==1){ prop=sort(c(0,sample(1:17,2),18,20)) a=sort(dist(prop)) if ((a[1]==1)&&(a[2]==2)&&(a[3]==4)&&(a[8]==14)) break() }

**R**emoving 18 from the above takes about the same time! A solution (modulo permutations) is *0, 13, 14, 18, 20*.

Filed under: R, Statistics Tagged: dist(), Le Monde, mathematical puzzle, R

To

**leave a comment**for the author, please follow the link and comment on their blog:**Xi'an's Og » R**.R-bloggers.com offers

**daily e-mail updates**about 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.