How many ways are there to arrange two digits into an n digit number, when both digits must be used? I know the answer to this question is $2^n-2$, but I am unsure of how this answer is gotten. Could someone please explain to me how the answer is gotten step by step? Also, how many ways would there be to arrange 3,4, or 5 digits into an n digit number? Thanks!
 A: Each of the $n$ digits can either be number $A$ or number $B$, for a total of $2^n$ possibilities.  But you can't have the number that is all $A$'s and the number that is all $B$'s, for a final answer of $2^n-2$
A: Suppose we have $n$ digits, where $n$ is a fixed positive integer and $a$ and $b$ are the two digits chosen to form the $n$ digit number. Now first of all, to make an arrangement, you would have to choose how many of each $a$'s and how many $b$'s  your number would have and notice that the sum of the number of $a$'s and $b$'s is $n$. So given a fixed $k$, where $k$ is the number of $a$'s, the number of possible arrengments with $k$ $a$'s and $n-k$ $b$'s would be $$\frac{n!}{k!(n-k)!}$$
however, we must choose at least one $a$ and at least one $b$ so $1\le k\le n-1$ for this reason, the total number of possibiliteis would be the sum from $k=1$ to $k=n-1$. If notice, this is the sum of the terms in the $n^{th}$ of the Pascal's Triangle (which equals $2^n$) except for the terms with $k=0$ and $k=n$ which are both 1, so you have to subtract 2
A: Just to make things simpler, let's assume for the time being that neither digit is $0$:  We'll pretend that one digit is $1$, and the other digit is $2$.
Write out $n$ blanks, one for each place.  We can write a $1$ or a $2$ in the first place, a $1$ or a $2$ in the second place, a $1$ or a $2$ in the third place, and so on, for each of the $n$ places.
The number of ways to fill in those blanks is $2$ (for the first choice of $1$ or $2$), times $2$ (for the second choice of $1$ or $2$), times $2$ (for the third choice of $1$ or $2$), and so on, for $n$ choices in all.  That's $n$ factors of $2$, or $2^n$ in all.
From this count must be subtracted two numbers: the one consisting of all $1$'s, and the one consisting of all $2$'s.  Thus, the final count is $2^n-2$.

This works for $0$'s, too, so long as leading $0$'s are permitted (for instance, we permit the number $00220$ for $n = 5$).  If leading $0$'s are not permitted, then the count is $2^n-n-1$ (if numbers shorter than $n$ digits are permitted) or $2^{n-1}-1$ (if the numbers must be exactly $n$ digits long), for reasons I can go into if you're interested.
A: If the number must contain both digits then the number of ways is
$$
\sum_{k=1}^{n-1} \left(
\begin{array}{c}
n\\
k
\end{array}\right) = 2^n - 2
$$
Suppose the two digits are $a$ and $b$, $a\neq b$. Then the number of ways to choose $k$ of the digits to be equal to $a$ is
$$
\left(
\begin{array}{c}
n\\
k
\end{array}\right)
$$
All remaining digits are $b$, so there is no choice to make for them. Now you simply sum up all the possibilities $(k = 1,\ldots,n-1)$, ignoring the cases $k = 0,n$, in which the number would only contain a single digit.
