## Le Monde puzzle [#1043] An arithmetic Le Monde mathematical puzzle :

A number is “noble” if all its digits are different and if it is equal to the average of all numbers created by permuting its digits. What are the noble numbers?

There is no need for simulation when plain enumeration works. After failing to install the R packge permutations, I installed the R package permute, which works, although (a) the function allPerm does not apply directly to a vector of characters or numbers but only to its size:

```> allPerms(c("a","r","h"))
[,1] [,2] [,3]
[1,]    1    3    2
[2,]    2    1    3
[3,]    2    3    1
[4,]    3    1    2
[5,]    3    2    1
```

and (b) as seen above the function does not contain “all” permutations since it misses the identity permutation.  Which ends up being fine for solving this puzzle. Using a bit of digit-character manipulation

```findzol=function(N=2){
for (u in 1:(10^N-1)){
digz=strsplit(as.character(u),"")[]
if (length(digz)<N)
digz=c(rep("0",N-length(digz)),digz)
if (length(unique(digz))==N){
permz=apply(matrix(digz[allPerms(1:N)],
ncol=N),2,as.numeric)
if (mean(permz%*%10^{(N-1):0})==u) print(u)}}}
```

I found solutions for N=3

```> findzol(3)
 370
 407
 481
 518
 592
 629
```

and none for N=4,5,6. Le Monde gives solutions for N=9, which is not achievable by my code!

### 2 Responses to “Le Monde puzzle [#1043]”

1. Martyn Says:

For N=9 the problem simplifies because there are only 10 possibilities, i.e. which digit do you drop? You can then calculate the average over all digit permutations:

for (i in 1:10) { print(mean((0:9)[-i])*111111111) }

and keep the numbers that satisfy the permutation condition for noble numbers (unique digits, not containing the dropped digit)

• xi'an Says:

Very neat, Martyn!!!

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