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

*Related*

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