Le Monde puzzle [#827]

July 2, 2013
By

(This article was first published on Xi'an's Og » R, and kindly contributed to R-bloggers)

Back to R (!) for the current Le Monde puzzle:

Given an unknown permutation of the set {1,…,6}, written on the faces of a cube, there exist a sequence of summits such that increasing by one unit the three numbers of the faces sharing the successive summits in the sequence leads to identical values over all faces. What was the initial permutation? What is the minimal number of steps to reach equality?

My initial worry was to rewrite the summit constraint(s) in a manageable way. I tried with a 6×8 matrix, calling 1 the bottom face and 6 the top face (which are thus the only two that cannot get changed at the same time):

```summits=matrix(0,6,8)
for (i in 2:5){
summits=1
summits=1}
```

First, I sought a random exploration of the faces. However, I did impose the smallest and largest values on the top and  bottom faces as they are the ones getting most and least updated compared with the other faces (?):

```solve=rep(0,10^3)
initia=matrix(0,6,10^3)
for (alea in 1:10^3){
faces=initia[,alea]=c(1,sample(2:5),6)
for (T in 1:100){
sumi=sample(1:8,1)
faces=faces+summits[,sumi]
if (diff(range(faces))==0) break()
}
if (diff(range(faces))==0){
solve[alea]=T}
}
```

The outcome is unsurprising in that the smallest number of summits is then 5, making all faces equal to 6. For a starting value equal to, e.g., {1,2,3,5,4,6}. (Something that tooks a [wee] while for me to understand was why removing the sample(2:5) in the above makes a difference.)

Filed under: R Tagged: Le Monde, mathematical puzzle, R

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...