Le Monde puzzle [#7]

March 26, 2011

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

The mathematical puzzle from the weekend edition of Le Monde from a few weeks ago was not too hard to solve by induction but my R code failed miserably! The puzzle was as follows:

A calculator is broken in such a way that it starts by exhibiting 0, then pressing 4, 6 or 0 keeps adding this figure to the right of the current number (if not zero), while pressing 2 divides the current number by 2. For instance, a possible sequence is

4 [press 4]
46 [press 6]
23 [press 2]
230 [press 0]

Is it possible to exhibit any integer?

I thus wrote the simple R code

strapply(as.character(n), ".", as.numeric)[[1]]
if (ok

which unfortunately runs very quickly into problems as can be seen by calling

> check(7)
Error in if (ok < length(xdigits)) { :
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In do.call(FUN, as.list(s[, j])) : NAs introduced by coercion
2: In do.call(FUN, as.list(s[, j])) : NAs introduced by coercion
3: In do.call(FUN, as.list(s[, j])) : NAs introduced by coercion

because the 2x…x2x7 value gets out of bounds…

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

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

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)