Le Monde puzzle [#954]

March 24, 2016

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

A square Le Monde mathematical puzzle:

Given a triplet (a,b,c) of integers, with a? Can you find the triplet (a,b,c) that produces the sum a+b+c closest to 1000?

This is a rather interesting challenge and a brute force resolution does not produce interesting results. For instance, using the function is.whole from the package Rpmfr, the R functions

ess <- function(a,b,k){
#assumes a


 while (b<1000*a){
  if (is.whole(sqrt(a+b))){
   while (k<100*b){
    if (is.whole(sqrt(a+k))&is.whole(b+k))
     if (ess(a,b,k)) break()

do not return any solution when a=1,2,3,4,5

Looking at the property that a+b,a+c,b+c, and a+b+c are perfect squares α²,β²,γ², and δ². This implies that

a=(δ+β)(δ-β), b=(δ+γ)(δ-γ), and c=(δ+α)(δ-α)

with 1<α<β<γ<δ. If we assume β²,γ², and δ² consecutive squares, this means β=γ-1 and δ=γ+1, hence

a=4γ, b=2γ+1, and c=(γ+1+α)(γ+1-α)

which leads to only two terms to examine. Hence writing another R function


and running a check for the smallest values of α and γ leads to the few solutions available:

> for (ga in 3:1e4) 
for(al in 1:(ga-2)) 
if (ess(abc(al,ga))) print(abc(al,ga))
[1] 80 41 320
[1] 112 57 672
[1] 192 97 2112
[1] 240 121 3360
[1] 352 177 7392
[1] 416 209 10400
[1] 560 281 19040
[1] 640 321 24960
[1] 816 409 40800
[1] 912 457 51072

Filed under: Kids, R Tagged: Alice and Bob, is.whole, Le Monde, mathematical puzzle, R, recursive function, Rmpfr

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

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

Comments are closed.


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)