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’)

}

}

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.

]]>