## Le Monde puzzle [#1075]

**A **new Le Monde mathematical puzzle in the digit category:

Find the largest number such that each of its internal digits is strictly less than the average of its two neighbours. Same question when all digits differ.

For instance, n=96433469 is such a number. When trying pure brute force (with the usual integer2digits function!)

le=solz=3 while (length(solz)>0){ solz=NULL for (i in (10^(le+1)-1):(9*10^le+9)){ x=as.numeric(strsplit(as.character(i), "")[[1]]) if (min(x[-c(1,le+1)]<(x[-c(1,2)]+x[-c(le,le+1)])/2)==1){ print(i);solz=c(solz,i); break()}} le=le+1}

this is actually the largest number returned by the R code. There is no solution with 9 digits. Adding an extra condition

le=solz=3 while (length(solz)>0){ solz=NULL for (i in (10^(le+1)-1):(9*10^le+9)){ x=as.numeric(strsplit(as.character(i), "")[[1]]) if ((min(x[-c(1,le+1)]<(x[-c(1,2)]+x[-c(le,le+1)])/2)==1)& (length(unique(x))==le+1)){ print(i);solz=c(solz,i); break()}} le=le+1}

produces n=9520148 (seven digits) as the largest possible integer.

## Leave a Reply