Le Monde puzzle [#739]

September 9, 2011
By

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

The 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[c(2:ticks,1)]-
  states[c(ticks,1:(ticks-1))])==0)
  plotstate(t,states)
  }

Given 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


The 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:

But I am sure this is not what the authors of Le Monde puzzle meant…


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

To leave a comment for the author, please follow the link and comment on his blog: Xi'an's Og » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: 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: , ,

Comments are closed.