Le Monde puzzle [#7]
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
0 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
library(gsubfn) digitBase=function(n){ strapply(as.character(n), ".", as.numeric)[[1]] } check=function(x){ step=0 xdigits=digitBase(x) ok=sum(xdigits==0)+sum(xdigits==4)+sum(xdigits==6) if (ok<length(xdigits)){ y=2*x step=1+check(y) } step }
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…
March 31, 2011 at 11:23 pm
Hello. I am trying to find the weekly puzzle on the le monde website and have had no luck. Is this content available online or do I need to subscribe? If it isn’t available online do you know if anyone post the puzzle weekly (before solving it)?
April 1, 2011 at 6:40 am
Alas, thrice alas, the puzzle is not available on line, not even to us subscribers. I think the reason is that the puzzle creators, Busser and Cohen, publish books out of those puzzles. I only found another site posting the puzzle and its resolution, concentrating on geometry puzzles. As I put the (abridged) puzzle as a quote in my post, you may stop reading at this point… Although I rarely include the mathematical solution to the puzzle, focusing rather on the R exercise.
March 30, 2011 at 12:15 am
[…] mathematical puzzle from Le Monde that relates to a broken calculator (skipping the useless […]