# Le Monde puzzle [#843]

December 13, 2013
By

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

A straightforward Le Monde mathematical puzzle:

Find integers x with 4 to 8 digits which are (a) perfect squares x=y² such that [x/100] is also a perfect square; (b) perfect cubes x=y³ such that [x/1000] is also a perfect cube; (c) perfect cubes x=y³ such that [x/100] is also a perfect cube (where [y] denotes here the integer part).

I first ran an R code in the train from Luxembourg that was not workng (the code not the train!), as I had started with

cubs=(34:999)^2 #perfect square
cubs=cubs[cubs%%10>0] #no 0 at the end
trubs=trunc(cubs/100)
difs=apply(abs(outer(cubs,trubs,"-")),2,min)
mots=cubs[difs==0]


If namely too high a lower bound in the list of perfect squares. It thus returned an empty set with good reasons. Using instead

cubs=(1:999)^2 #perfect square


produced the outcome

> mots
[1]  121  144  169  196  441  484  961 1681


and hence the solution 1681. For the other questions, I used

trubs=(1:999)^3
for (i in 1:length(trubs)){
cubs=trubs[i]*100+(1:99)
sol=abs(cubs-round(exp(log(cubs)/3))^3)
if (min(sol)==0){ print(cubs[sol==0])}
}


and got the outcome

[1] 125
[1] 2744


which means a solution of 2744. Same thing for

trubs=(1:999)^3
for (i in 1:length(trubs)){
cubs=trubs[i]*1000+(1:999)
sol=abs(cubs-round(exp(log(cubs)/3))^3)
if (min(sol)==0){ print(cubs[sol==0])}
}


and

[1] 1331 1728


and two solutions. (Of course, writing things on a piece of paper goes way faster…)

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