**T**he weekend puzzle in *Le Monde* this week is again about a clock. Now, the clock has one hand and x ticks where a lamp is either on or off. The hand moves from tick to tick and each time the lights go on or off depending on whether or not both neighbours were in the same state the previous time. Here is my R code that describes the evolution of the clock according to this rule:

library(animation)
ani.options(interval=1)
plotstate=function(t,state){
ticks=length(state)
plot(c(0,sin(t*2*pi/ticks)), c(0,cos(t*2*pi/ticks)),type="l",col="tomato",
xlim=c(-1.2,1.2),ylim=c(-1.2,1.2),axes=FALSE,xlab="",ylab="")
on=(1:ticks)[state==1]*2*pi/ticks
points(cos(on),sin(on),col="gold",cex=2,pch=19)
on=(1:ticks)[state==0]*2*pi/ticks
points(cos(on),sin(on),col="sienna",cex=2,pch=19)
ani.pause()
}
ticks=12
states=as.integer((runif(ticks)<.5))
plotstate(t=0,states)
for (t in 1:ticks){
states=1-((states-
states)==0)
plotstate(t,states)
}

**G**iven the initial state (0,1,0,1,1,0,0,0,1,0,0,1), the question is to provide the state after one hour

> states
[1] 0 0 0 1 1 1 0 0 1 1 0 1

**T**he next question is rather unclear: *with a different number of ticks, is it possible to forecast the state of the clock one hour later*? My answer is to run the R code with the appropriate value for ticks and observe the result, since the update rule is deterministic. For instance, here is the result for 18 ticks:

**B**ut I am sure this is not what the authors of *Le Monde* puzzle meant…

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

*Related*

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

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...

**Tags:** Le Monde, mathematical puzzle, R