Post by ProginoskesPost by Arturo MagidinPost by Gunnar GHere's a problem I've been struggling with.
An integer is called increasing if the no digit is smaller than the integer
to the left of it, i.e. 2449 is increasing.
The integer is said to be decreasing if no digit is larger than the integer
to the left of it.
Now, how many of the integers below one million is increasing or decreasing?
I'd say there are 10000.
First, the number of increasing numbers must be the same as the number of
decreasing since an increasing number is a decreasing number if the digits
are reversed, and vice versa.
This argument does not fly. The decreasing numbers 1, 10, 100, 1000,
10000, 100000, etc. all yield the same increasing number when
reversed: 1.
When you pad 0's on the left, 1 does not become decreasing (00001), nor
10 (00010), etc.
Oh, for crying out loud. Just do the computations for numbers with one
or two digits. There are 55 increasing numbers; there are 64
decreasing numbers with 1 or 2 digits. There is a total of 100 numbers
between 0 and 99 which are either increasing or decreasing or both: we
counted the 9 positive multiples of 11, and the 10 single digit
numbers twice each (hardly surprising, since there's not enough room
to "turn around"). Padding with zeros on the left was done so that the
function f(n) counted all increasing numbers with at most n
digits. But all of this was predicated on the claim that the number of
increasing and of decreasing numbers is equal.
If you pad with zeros on the left, and f(n) is the number of
increasing numbers with exactly n digits counting the leading zeros,
then f(n)-1 (dropping 00000000) is equal to the decreasing
numbers with EXACTLY n digits (which of course has no leading
zeros). The only exception is when n=1, in which case f(1) is both the
increasing and the decreasing numbers.
So there is an asymmetry between increasing and decreasing numbers:
while f(3) will tell you exactly how many increasing numbers there are
between 0 and 999, inclusively, it will only tell you how many
decreasing numbers there are between 100 and 999; if you want to know
whow many decreasing numbers there are between 0 and 999 you need to
take f(1)+f(2)+f(3) - 2.
And in general, if f(n) gives you the number of increasing numbers
between 0 and 10^n-1 (i.e., up to n digits), then the number of
decreasing numbers between 0 and 10^n - 1 is
f(1) + ... + f(n) - (n-1).
Yes. And his answer is correct for increasing numbers of up to n
digits; it is not, however, correct for either decreasing or
(increasing or decreasing or both). Neither is yours.
Post by ProginoskesThe number of ways to
choose n digits where order doesn't matter, and where repetition is
allowed is
f(n) = C(n + 9, n)
There is only one way to order such a "set" of numbers to make an
increasing number, and only one way to order them to make a decreasing
number, so every "combination" of n digits will produce 2 monotonic
(increasing or decreasing) numbers ... UNLESS the same number is chosen
n times. So the number of n-digit monotonic numbers (where 0 counts as
a leading digit) is
2 * C(n + 9, n) - 9.
When n=6, this solves the OP's problem.
Let's try your formula to calculate the number of increasing and
decreasing numbers between 0 and 99: here n = 2, so we have
2*C(11,2) - 9 = 11(10) - 9 = 101.
Apparently there are one hundred and one numbers between 0 and 99.
There is an asymmetry between increasing and decreasing numbers; the
original poster, matt27189, and you, seem to have missed it.
You'll note that C(11,2) = 55 gives the correct number of increasing
numbers. But 55 is the number of decreasing numbers with EXACTLY two
digits. If you want the number of decreasing numbers with 1 or 2
digits, you need C(11,2)+C(10,1)-(2-1) = 55 + 10 - 1 = 64.
How many repeats? You have 10 repeats for the 1 digit, and after that
you have 9 repeats for every extra digit. So you have 9n+1 repeats. So
the correct formula would be
[Sum_{i=1}^{n}C(n+9,n)] - (n-1) decreasing numbers
+ C(n+2,n) increasing numbers
- (9n + 1) repeats.
--
======================================================================
"It's not denial. I'm just very selective about
what I accept as reality."
--- Calvin ("Calvin and Hobbes")
======================================================================
Arturo Magidin
***@math.berkeley.edu