Le Monde puzzle [#904.5] About this #904 arithmetics Le Monde mathematical puzzle:

Find all plural integers, namely positive integers such that (a) none of their digits is zero and (b) removing their leftmost digit produces a dividing plural integer (with the convention that one digit integers are all plural).

a slight modification in the R code allows for a faster exploration, based on the fact that solutions add one extra digit to solutions with one less digit:

First, I found this function on Stack Overflow to turn an integer into its digits:

pluri=plura=NULL
#solutions with two digits
for (i in 11:99){

dive=rev(digin(i)[-1])
if (min(dive)&gt;0){
dive=sum(dive*10^(0:(length(dive)-1)))
if (i==((i%/%dive)*dive))
pluri=c(pluri,i)}}

for (n in 2:6){ #number of digits
plura=c(plura,pluri)
pluro=NULL
for (j in pluri){

for (k in (1:9)*10^n){
x=k+j
if (x==(x%/%j)*j)
pluro=c(pluro,x)}
}
pluri=pluro}

which leads to the same output

&gt; sort(plura)
 11 12 15 21 22 24 25 31 32 33 35 36
 41 42 44 45 48 51 52 55 61 62 63 64
 65 66 71 72 75 77 81 82 84 85 88 91
 92 93 95 96 99 125 225 312 315 325 375 425
 525 612 615 624 625 675 725 735 825 832 912
 915 925 936 945 975 1125 2125 3125 3375 4125
 5125 5625
 6125 6375 7125 8125 9125 9225 9375 53125
 91125 95625

7 Responses to “Le Monde puzzle [#904.5]”

1. Miff Says:

Why doesn’t e.g. 714 appear as output? I get 92 numbers under 10^5 with the code:

n <- 1:(1e5)
n <- n[!grepl("0",n)]
a <- expand.grid(first=1:9,second=n)

l <- as.numeric(paste0(a\$first,a\$second)) %% a\$second == 0
sort(as.numeric(paste0(a\$first[l],a\$second[l])))

• xi'an Says:

I am alas strongly prejudiced against this number 714…!

More to the point, 714 is not acceptable because 14 is not a multiple of 4. I realise now this constraint is missing from my puzzle, thank you!

• Martin Says:

Now thats a nice piece of code :)

2. Martin Says:

I like those puzzles. And gave it a chance as well. The advantage of my approach is that it doesn’t use any methods on strings. So there is no conversion or splitting necessary :)
I think its a lot faster. If you have any ideas how to further improve it, let me know :)

uBound = 10000
leMonde = function(uBound) {
j = 1
result = vector()
for(i in 11:uBound) {
l = floor(log10(i))+1
o = sapply(10^(1:(l-1)), function(x) { i %% x } )
if(length(unique(o)) == length(o) & o != 0) {
if(i %% o[(l-1)] == 0) {
result[j] = i
j = j+1
}
}
}
return(result)
}

Best,
Martin

• Martin Says:

In fact my routine isn’t faster XD I assumed it would be. But I guess the sapply term adds more process time than it takes…

• xi'an Says:

Thank you for the alternative. Indeed, sapply() is often a front for more loops, so does not gain much time…

• xi'an Says:

Update: the text of the puzzle was missing a crucial component, namely the constraint that the dividers themselves are plural. So, e.g., 714 does not work because 4 is not a divider of 14, even though 14 is a divisor of 714…

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