**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]

**I**f 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

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