I've seen a post which was started as a joke saying : "Well, Guess the code ?" (4 digit code)
Apart from the joke , I was thinking , well , how many combinations do we have here , knowing that 8 and 0 are a must.
Sure ,the logic says :
2^4 minus (bad options which is 0000,8888) = 14
But this is not a mathematical calculation but a human logic being involved.
I was thinking about something like this:
Let's take 8. It has 4 places to be one or more times
But if it appears first , then at least one 0 must be on the other 3 places ... and so on and so on
Same for the 0 : It has 4 places to be one or more times
But if it appears first , then at least one 8 must be on the other 3 places ... and so on and so on
Question:
How can I yield 14 by a mathematical proof ? (and not by a human logic : "let's take all the options and remove the bad combinations")
EDIT (after some answers) The demo above was an easy part. But I'm after more generalized formula :
Say not only $8$ and $0$ were bold. let's say $0$, $8$, $5$, $2$ were bold and the password was $5$ length long . So then what? removing the count of all $00000$, $88888$, $55555$, $22222$ AND $08555$ (becuase $2$ and $0$ must be present also)? and $08222$? ( becuase $5$ and $0$ must be present also).......?? Do you see what I mean ? Human logic is more complicated here. It is not a general formula , but specific to this case. I'm after a generalized formula
In other words the question can be reduced to :
How many options can we select from $N$ numbers , at length of $L$ ( $L\geq N$) where at least each number from $N$ must appear
so N = 0,8,5,2
L = 5
08520 valid
85200 valid
08555 invalid (missing 2)
08222 invalid (missing 5)
etc...

First of all, your original argument looks like a mathematical proof to me; you want to count all sequences of $0$'s and $8$'s of length $4$ that contain at least one $0$ and one $8$. That's the same as all sequences of length $4$ that aren't all $0$'s or all $8$'s, and so you get $2^4-2=14$.
But your second line of thought gives another way to reach the same conclusion, albeit more roundabout:
A sequence must start with either $0$ or $8$:
This yields a total of $7+7=14$ sequences. Of course this is in essence the same reasoning as your original argument, with a small adjustment by distinguishing cases based on the first digit. You could also keep distinguishing cases for the second, third and fourth digit and in this way count all sequences separately. This comes down to drawing a tree diagram of all possible sequences.
For the more general case in the edit, the inclusion-exclusion principle is of great help. The generality in which it is stated on the linked page may be a bit intimidating, but the idea is the following;
EDIT: I just saw that the example in your edit concerns sequences of length $5$, whereas my example treats sequences of length $4$. The number of such sequences of length $5$ is $240$, which you can verify yourself with this method.
EDIT2: I just saw that you asked for a formula for the number of sequences of length $L$ that contain each of $N$ digits at least once, with $N\leq L$. The above shows that the number of possible sequences is $$\sum_{i=0}^N(-1)^i\binom{N}{i}(N-i)^L.$$ In particular, for the original question on the number of sequences of length $L=4$ with the $N=2$ digits $0$ and $8$, we indeed get $$\sum_{i=0}^N(-1)^i\binom{N}{i}(N-i)^L=\binom{2}{0}2^4-\binom{2}{1}1^4+\binom{2}{0}0^4=1\times16-2\times1+1\times0=14.$$