Le Monde puzzle [#1133]

A weekly Monde current mathematical puzzle that reminded me of an earlier one (but was too lazy to check):

If ADULE-ELUDA=POINT, was is the largest possible value of POINT? With the convention that all letters correspond to different digits and no digit can start with 0. Same question when ADULE+ELUDA=POINT.

The run of a brute force R search return 65934 as the solution (codegolf welcomed!)

dify<-function(adule) 
  (sum(adule*10^(4:0))-sum(rev(adule)*10^(4:0)))
num2dig<-function(dif) (dif%/%10^(0:4))%%10
sl=NULL
for (t in 1:1e6){
  adule=sample(0:9,5)
  while((dify(adule)<=0)||(!prod(adule[c(1,5)])))
     adule=sample(0:9,5)
point=rev(num2dig(dify(adule)))
if ((!sum(duplicated(point)))&(prod(point%in%(0:9)[-adule-1])))
  sl=rbind(sl,c(adule,point))}
sl=as.matrix(distinct(as.data.frame(sl),.keep_all = TRUE))

where distinct is a dplyr R function.

> 94581-18549
[1] 76032

The code can be easily turned into solving the second question

> 31782+28713
[1] 60495

4 Responses to “Le Monde puzzle [#1133]”

  1. szcfweiya Says:

    Hi Prof. Robert,

    There might be some typos:

    – in your question statement, `ELUDE` should be `ELUDA`,
    – in your `dify` function, redundant `point` argument
    – and `dify(aluda)` should be `dify(alude)` in the main code.

    And you said the solution is 65934 before your code, but you return 76032 later.

    I tried to make a slight modification, replacing `sample` with `for loop`, which seems shorter.

    “`R
    dify<-function(alude)
    (sum(alude*10^(4:0))-sum(rev(alude)*10^(4:0)))
    num2dig0)rev((dif%/%10^(0:4))%%10)else numeric(5)
    sl=NULL
    for (t in (1e5-1):1e4){
    adule=num2dig(t)
    if (!sum(duplicated(adule))){
    point=num2dig(dify(adule))
    if ((!sum(duplicated(point)))&&(prod(point%in%(0:9)[-adule-1])))
    sl=rbind(sl,c(adule,point))}}
    “`

  2. […] article was first published on R – Xi'an's Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) […]

  3. […] by data_admin [This article was first published on R – Xi’an’s Og, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.