\r\n" );
document.write( "I think you need to insert the word \"NEIGHBORING\" in there like this:\r\n" );
document.write( "\r\n" );
document.write( "How many 7-digit numbers can be formed using the digits 1, 2, 3, 4, and 5,\r\n" );
document.write( "provided that any two distinct NEIGHBORING digits in this number are\r\n" );
document.write( "consecutive?\r\n" );
document.write( "\r\n" );
document.write( "Otherwise, without the word \"NEIGHBORING\", the only solutions would be these 9:\r\n" );
document.write( "1111111, 2222222, 3333333, 4444444, 5555555, where there would be no distinct\r\n" );
document.write( "digits. Or these, 1222222, 2333333, 3444444, 4555555, where the only distinct\r\n" );
document.write( "digits are consecutive. \r\n" );
document.write( "\r\n" );
document.write( "An even better way to state the problem would be this way:\r\n" );
document.write( "\r\n" );
document.write( "How many 7-digit numbers can be formed using the digits 1, 2, 3, 4, and 5,\r\n" );
document.write( "provided that any two consecutive digits are also consecutive integers?\r\n" );
document.write( " \r\n" );
document.write( "I will also assume that by two integers being 'consecutive', that you mean the\r\n" );
document.write( "one on the right is 1 more than the one on the left, not vice-versa. \r\n" );
document.write( "\r\n" );
document.write( "I will assume the above is what you mean. If not, post again with clear\r\n" );
document.write( "explanation, and perhaps a sample or two of what you want to be enumerated. \r\n" );
document.write( "\r\n" );
document.write( "------------------------------------------------\r\n" );
document.write( "\r\n" );
document.write( "This asks for the number of 7-digit numbers whose 7 digits left to right form a\r\n" );
document.write( "non-decreasing sequence of digits, beginning with p and ending with q, such that\r\n" );
document.write( "
. The smallest is 1111111 and the largest is 5555555. All digits\r\n" );
document.write( "
will be included. We need to find the number of 7 digit numbers\r\n" );
document.write( "of the form p-----q, for all p,q,
\r\n" );
document.write( "\r\n" );
document.write( "I cannot remember all the partition formulas, so I'll have to derive them all\r\n" );
document.write( "from the method of stars and bars.\r\n" );
document.write( "\r\n" );
document.write( "To illustrate, let's pick the sample 2334445. There is 1 two, then 2 threes,\r\n" );
document.write( "then 3 fours, and finally 1 five.\r\n" );
document.write( "This sample illustration is the partition of 7 which does not contain any 0's:\r\n" );
document.write( "1+2+3+1 = 7, \r\n" );
document.write( "which corresponds to the partition of 3 which does contain 0's (subtracting 1\r\n" );
document.write( "from each of the 4 terms on the left, and subtracting 4 from the term on the\r\n" );
document.write( "right):\r\n" );
document.write( "\r\n" );
document.write( "0+1+2+0 = 3 \r\n" );
document.write( "\r\n" );
document.write( "which we write as\r\n" );
document.write( "\r\n" );
document.write( " 0| 1| 2| 0\r\n" );
document.write( "\r\n" );
document.write( "Now we replace each number by that number of stars, leaving the first and last\r\n" );
document.write( "empty since they are 0's:\r\n" );
document.write( " | *|**|\r\n" );
document.write( "\r\n" );
document.write( "Thus, the number of required 7-digit numbers of the form 2-----5 is \r\n" );
document.write( "\r\n" );
document.write( "
\r\n" );
document.write( "\r\n" );
document.write( "for there is a total of 6 stars and bars, and we can choose any 3 of the 6\r\n" );
document.write( "positions to place the bars in \r\n" );
document.write( "\r\n" );
document.write( "This, incidentally, is also the number of required 7-digit numbers of the form\r\n" );
document.write( "1-----4. \r\n" );
document.write( "\r\n" );
document.write( "In general, the number of 7-digit numbers p-----q where \r\n" );
document.write( "q and p differ by k is C(6,k)\r\n" );
document.write( "\r\n" );
document.write( "For the number-types 1------1, 2------2, ..., 5-----5 \r\n" );
document.write( "there are
\r\n" );
document.write( "\r\n" );
document.write( "For the numbers 1------2, 2------3, ..., 4-----5 \r\n" );
document.write( "there are
\r\n" );
document.write( " \r\n" );
document.write( "For the numbers 1------3, 2------4, 3-----5 \r\n" );
document.write( "there are
\r\n" );
document.write( "\r\n" );
document.write( "For the numbers 1------4, 2-----5 \r\n" );
document.write( "there are
\r\n" );
document.write( "\r\n" );
document.write( "For the number 1------5 (actually 12345) \r\n" );
document.write( "\r\n" );
document.write( "there are
\r\n" );
document.write( "\r\n" );
document.write( "So the answer is 5+24+45+40+15 = 129 <--ANSWER\r\n" );
document.write( "\r\n" );
document.write( "Ikleyn probably has all the partition formulas memorized and\r\n" );
document.write( "would write down the answer as a summation like this:\r\n" );
document.write( "\r\n" );
document.write( "
\r\n" );
document.write( "\r\n" );
document.write( "and probably even generalize it to this problem and answer as a summation:\r\n" );
document.write( "\r\n" );
document.write( "How many non-decreasing sequences of n positive integers can be formed from the\r\n" );
document.write( "integers {1,2,...,r} provided that any two consecutive terms are also\r\n" );
document.write( "consecutive integers. \r\n" );
document.write( "\r\n" );
document.write( "Edwin
\n" );
document.write( "