Testing for divisibility of numbers - follow-up
Precomputed table

I was able to get a much faster result by doing the following:


I precomputed a table which listed for each number, all the permutations of that number.  Only the lowest valid number contained its permutations.  For example, the number 102 contained the permutations: 102 120 201 210.  The entries for 120, 201, and 210 were empty.
I iterated through each number from 1 to MAX.  For each number, I checked whether each divisor divided into at least one of the permutations of the number.  If all divisors divided at least once, then the program was done and the lowest number was found.


When I say I precomputed a table, I mean that I wrote a separate program to dump a table of 1000000 ints into a C file.  I then modified that C file and turned the table into an array of 1000000 ints (a large file > 10MB, but only using about 4 MB at run time), and compiled that huge array into my program.  So I had something that looked like this:

int bigArray[] = {
    -1, -2, -3, -4, ..., -12, 21, -13, 31, ...,
    -102, 120, 201, 210, -103, ..., -999999, -1000000
};


I used negative numbers to denote the start of a new permutation and positive numbers to denote permutations of the entry.  Thus, the -12 and 21 above mean that 12 is the start of a new permutation and 21 is one of the permutations for it.

I have the code to generate the table and the code to use the table, but rather than post them here, I will leave it to the OP to use this idea and create their own code.

The precomputed table version seemed to be about 2x as fast as the previous version, but since the times were so small (0.03 vs 0.06 seconds), it's hard to say whether that measurement was really accurate.