## Le Monde puzzle [#1002]

Posted in Kids, R with tags , , , , , , , on April 4, 2017 by xi'an

For once and only because it is part of this competition, a geometric Le Monde mathematical puzzle:

Given both diagonals of lengths p=105 and q=116, what is the parallelogram with the largest area? and when the perimeter is furthermore constrained to be L=290?

This made me jump right away to the quadrilateral page on Wikipedia, which reminds us that the largest area occurs when the diagonals are orthogonal, in which case it is A=½pq. Only the angle between the diagonals matters. Imposing the perimeter 2s in addition is not solved there, so I wrote an R code looking at all the integer solutions, based on one of the numerous formulae for the area, like ½pq sin(θ), where θ is the angle between both diagonals, and discretising in terms of the fractions of both diagonals at the intersection, and of the angle θ:

```p=105
q=116
s=145
for (alpha in (1:500)/1000){
ap=alpha*p;ap2=ap^2;omap=p-ap;omap2=omap^2
for (beta in (1:999)/1000){
bq=beta*q;bq2=bq^2;ombq=q-bq;ombq2=ombq^2
for (teta in (1:9999)*pi/10000){
d=sqrt(ap2+bq2-2*ap*bq*cos(teta))
a=sqrt(ap2+ombq2+2*ap*ombq*cos(teta))
b=sqrt(omap2+ombq2-2*omap*ombq*cos(teta))
c=sqrt(omap2+bq2+2*omap*bq*cos(teta))
if (abs(a+b+c+d-2*s)<.01){
if (p*q*sin(teta)<2*maxur){
maxur=p*q*sin(teta)/2
sole=c(a,b,c,d,alpha,beta,teta)}}}}
```

This code returned an area of 4350, to compare with the optimal 6090 (which is recovered by the above R code when the diagonal lengths are identical and the perimeter is the one of the associated square). (As Jean-Louis Foulley pointed out to me, this area can be found directly by assuming the quadrilateral is a parallelogram and maximising in the length of one side.)

## Le Monde puzzle [#954]

Posted in Kids, R with tags , , , , , , on March 25, 2016 by xi'an

A square Le Monde mathematical puzzle:

Given a triplet (a,b,c) of integers, with a<b<c, it satisfies the S property when a+b, a+c, b+c, a+b+c are perfect squares such that a+c, b+c, and a+b+c are consecutive squares. For a given a, is it always possible to find a pair (b,c) such (a,b,c) satisfies S? 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 Rmpfr, the R functions

```ess <- function(a,b,k){
#assumes a<b<k
ess=is.whole(sqrt(a+b))&
is.whole(sqrt(b+k))&
is.whole(sqrt(a+k))&
is.whole(sqrt(a+b+k))
mezo=is.whole(sqrt(c((a+k+1):(b+k-1),(b+k+1):(a+b+k-1))))
return(ess&(sum(mezo==0)))
}
```

and

```quest1<-function(a){
b=a+1
while (b<1000*a){
if (is.whole(sqrt(a+b))){
k=b+1
while (k<100*b){
if (is.whole(sqrt(a+k))&is.whole(b+k))
if (ess(a,b,k)) break()
k=k+1}}
b=b+1}
return(c(a,b,k))
}
```

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=2γ+1, b=4γ, and c=(γ+1+α)(γ+1-α)

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

```abc=function(al,ga){
a=2*ga+1
b=4*ga
k=(ga+al+1)*(ga-al+1)
return(c(a,b,k))}
```

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] 41 80 41 320
[1] 57 112 672
[1] 97 192 2112
[1] 121 240 3360
[1] 177 352 7392
[1] 209 416 10400
[1] 281 560 19040
[1] 321 640 24960
[1] 409 816 40800
[1] 457 912 51072
```