Le Monde puzzle [#1109]
A digital problem as Le Monde current mathematical puzzle:
Noble numbers are such that they only involve different digits and are multiple of all their digits. What is the largest noble number?
Hmmmm…. Brute force? Since the maximal number of digits is 10, one may as well try:
k=soz=9 for (t in 1:1e3){ sol=1 while (sol<10^(k-1)){ u=sample(0:8,k);i=digit2int(u) if (max(i%%u[u>0])==0) soz=max(soz,sol<-i)}}
which returns 9875643120… (I made the conscious choice to exclude zero from the dividers. Which was not a choice spelled out in the original question.)
September 13, 2019 at 12:20 am
[…] 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 […]
September 9, 2019 at 5:09 pm
I think this is faster, and removes the chance that your “sample()” misses the winning value. (since we know the winner must end in an even digit followed by zero, I reduced the set of numbers for which we check divisibility)
flag = 0
startat = 987654312
getmax = 0
while (!flag){
getmax = max(startat%%c(2,3,6,7,8,9))
if (getmax == 0) {
# first see if it’s got repeated digits
sstr = unlist(strsplit(toString(startat),split=NULL) )
if (length(unique(sstr)) == length(sstr) ) flag = 1
} else startat = startat -1 # so don’t decrement if exiting
if ( startat == 0) {
flag = 1
cat(‘startat is zero’)
}
}
September 9, 2019 at 3:28 pm
Nice approach… what about biasing larger digits? (e.g. sample(0:9, 10, prob = (1:10)/55) )
If one’s got time, iterating logic could be changed to: while(sol < soz)
Building on the above, there's simple (but tedious to implement) heuristic to adapt sampling to new maximums — an overkill for this problem, but useful in generalizing this approach.
September 6, 2019 at 3:32 pm
OK, now solve it in a N-character numeric system. Brute force in base-60 might be tough :-) . I wonder what theorems exist for bounds on Noble numbers vs. base.
September 5, 2019 at 8:11 am
[…] 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) […]