# How limitations affect the number of possible pandigital numbers

First, I understand that the definition of "pandigital" can vary, somewhat, so for the purposes of this question, here's the definition we'll use:

"Positive and whole numbers that include each digit from 1 through 9, at least once and no more than once, and excluding the digit 0"

By this definition, all possible results will be 9 digits long. Also by this definition, the number of possible combinations is calculated as

9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1

with each position in the calculation indicating the number of possible options for each position in the number, and which equals 362,880 possible numbers that satisfy this simple requirement.

Now, lets start adding more limitations. The first limitation is that the first digit MUST be the digit "1". This means that there is now only 1 possibility, instead of 9, for that first digit, so the calculation changes from

9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1

to

1 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1

and now there are only 40,320 possible combinations. Still pretty easy and straight forward.

Next limitation, the second digit can be either a 2, 5, 6, or 8. This doesn't change the single option for the first position, and it reduces the number of options for the second position from 8 down to 4. I believe (please correct me if I'm wrong in this assumption, as the rest of this question will become irrelevant if I am) this changes the calculation from

1 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1

to

1 x 4 x 7 x 6 x 5 x 4 x 3 x 2 x 1

Here's where I run in to trouble. The third "limitation" is actually a variable set of limitations, and the variation is based on which digit is selected in position 2 of the 9 digit number. I'll put the set of limitations in list form for clarity:

1. If the second digit is a 2, then the third digit can be either 6, 9, 5, 7, or 4. Five possible options

2. If the second digit is a 5, then the third digit can be either 2, 3, 4, 6, 7, or 8. Six possible options

3. If the second digit is a 6, then the third digit can be either 2, 3, 5, 7, 8, or 9. Again six possible options

4. If the second digit is an 8, then the third digit can be either 3, 4, 5, 6, 7, or 9. Another six possible options

So none of the options allow more than 6 possibilities. However, among all the possible options for the third digit of the number, all 8 remaining digits (other than 1, from the first position digit) is still available one way or another.

And now the actual question: For this third limitation (or set of limitations) how do I calculate the number of possible combinations remaining?

Is it

1 x 4 x 8 x 7 x 6 x 5 x 4 x 3 x 2

or

1 x 4 x 8 x 6 x 5 x 4 x 3 x 2 x 1

because all 8 digits can be selected somehow in the third position, as long as the correct digit is selected in position 2?

Is it still just

1 x 4 x 7 x 6 x 5 x 4 x 3 x 2 x 1

because it can't have been increased when only limitations are introduced, and not exceptions?

Is it

1 x 4 x 6 x 6 x 5 x 4 x 3 x 2 x 1

because Six is the highest number of possible options based on the previous digit?

Is it

1 x 4 x 5 x 6 x 5 x 4 x 3 x 2 x 1

because the first option has only 5 possibilities, and acts as an overall limiting factor?

is it something else I haven't considered?

• How many possibilities are there for the leftmost three digits? Say there are $N$ (You can practically count them by hand, if needed.) For each of these possibilities, if I read this right, there are the same number of possibilities for the remaining six digits, say $M$ possibilities for a given first three digits. Then there are $MN$ possible numbers in all. – Steve Kass Apr 11 at 20:27
• @SteveKass There are 23 possible combinations for the first 3 digits, 5+6+6+6, from the set of limitations at the third step. Is it as simple as 23 x 6 x 5 x 4 x 3 x 2 x 1 ? – Dalila Apr 11 at 20:31
• @Dalila: yes, that is correct. When you have restrictions like this you often have to count each case and add them together at the end. The simplification here was that once you got through the first three digits there were no more restrictions. – Ross Millikan Apr 11 at 20:32
• @RossMillikan There will be more restrictions later, but in this question I was looking for the process of determining the calculation, rather than determining the final outcome after all restrictions. At each level of the process a new set of more complex restrictions is added so putting them all in a question wouldn't be feasible. At each step the restrictions get more complex, because there are more possible combinations from the previous step. But I think between you and Steve, I now have what I need to work through the rest of the process ... – Dalila Apr 11 at 20:36