All 0:9 pandigital numbers.
Numbering the positions \(d_1\) to \(d_10\), certain conditions have to be met, eg \(d_2d_3d_4\) have to be divisible by 2. Increasing the “window” the three digits have to be divisible by the consecutive primes.
Generating all the potential pandigital numbers (as individual numbers)
library(gtools)
test <- permutations(10,10,c(0:9))
We now have \(d_6\) in column 6. And it needs to be either 0 or 5.
test <- subset(test,test[,6]%in%c(05))
\(d_4\) needs to be even:
test <- subset(test,test[,4]%in%c(0,2,4,6,8))
\(d_3d_4_d5\) needs to be divisible by 3:
test <- subset(test,((test[,3]*100+test[,4]*10+test[,5])%%3)==0)
\(d_5d_6d_7\) must be divisible by 7
test <- subset(test, ((test[,5]*100+test[,6]*10+test[,7])%%7)==0)
\(d_6d_7d_8\) must be divisible by 11:
test <- subset(test, ((test[,6]*100+test[,7]*10+test[,8])%%11)==0)
\(d_7d_8d_9\) must be divisible by 13:
test <- subset(test, ((test[,7]*100+test[,8]*10+test[,9])%%13)==0)
And finally, \(d_8d_9d_10\) must be divisible by 17:
test <- subset(test, ((test[,8]*100+test[,9]*10+test[,10])%%17)==0)
Collapse the surviving numbers and convert to numeric:
answer <- sum(as.numeric(apply(test,1,paste, collapse="")))