Question 1208378
<pre>
I think you need to insert the word "NEIGHBORING" in there like this:

How many 7-digit numbers can be formed using the digits 1, 2, 3, 4, and 5,
provided that any two distinct NEIGHBORING digits in this number are
consecutive?

Otherwise, without the word "NEIGHBORING", the only solutions would be these 9:
1111111, 2222222, 3333333, 4444444, 5555555, where there would be no distinct
digits.  Or these, 1222222, 2333333, 3444444, 4555555, where the only distinct
digits are consecutive. 

An even better way to state the problem would be this way:

How many 7-digit numbers can be formed using the digits 1, 2, 3, 4, and 5,
provided that any two consecutive digits are also consecutive integers?
 
I will also assume that by two integers being 'consecutive', that you mean the
one on the right is 1 more than the one on the left, not vice-versa. 

I will assume the above is what you mean.  If not, post again with clear
explanation, and perhaps a sample or two of what you want to be enumerated. 

------------------------------------------------

This asks for the number of 7-digit numbers whose 7 digits left to right form a
non-decreasing sequence of digits, beginning with p and ending with q, such that
{{{1<=p<=q<=5}}}. The smallest is 1111111 and the largest is 5555555. All digits
{{{p<=x<=q}}} will be included. We need to find the number of 7 digit numbers
of the form p-----q, for all p,q, {{{1<=p<=q<=5}}}  

I cannot remember all the partition formulas, so I'll have to derive them all
from the method of stars and bars.

To illustrate, let's pick the sample 2334445.  There is 1 two, then 2 threes,
then 3 fours, and finally 1 five.
This sample illustration is the partition of 7 which does not contain any 0's:
1+2+3+1 = 7, 
which corresponds to the partition of 3 which does contain 0's (subtracting 1
from each of the 4 terms on the left, and subtracting 4 from the term on the
right):

0+1+2+0 = 3 

which we write as

 0| 1| 2| 0

Now we replace each number by that number of stars, leaving the first and last
empty since they are 0's:
  | *|**|

Thus, the number of required 7-digit numbers of the form 2-----5 is 

{{{C(6,3)=6!/(3!4!)=20}}}

for there is a total of 6 stars and bars, and we can choose any 3 of the 6
positions to place the bars in 

This, incidentally, is also the number of required 7-digit numbers of the form
1-----4. 

In general, the number of 7-digit numbers p-----q where 
q and p differ by k is C(6,k)

For the number-types 1------1, 2------2, ..., 5-----5 
there are {{{5*C(6,0)=5*6!/(0!6!)=5*1=5}}} 

For the numbers 1------2, 2------3, ..., 4-----5 
there are {{{4*C(6,1)=4*6!/(1!5!)=4*6=24}}}
   
For the numbers 1------3, 2------4, 3-----5 
there are {{{3*C(6,2)=3*6!/(2!4!)=3*15=45}}}

For the numbers 1------4, 2-----5 
there are {{{2*C(6,3)=2*6!/(3!3!)=2*20=40}}}

For the number 1------5 (actually 12345) 

there are {{{1*C(6,4)=2*6!/(4!2!)=1*15=15}}}

So the answer is 5+24+45+40+15 = 129   <--ANSWER

Ikleyn probably has all the partition formulas memorized and
would write down the answer as a summation like this:

{{{sum((5-k)*C(6,k),k=0,4)}}}

and probably even generalize it to this problem and answer as a summation:

How many non-decreasing sequences of n positive integers can be formed from the
integers {1,2,...,r} provided that any two consecutive terms are also
consecutive integers.  

Edwin</pre>