Probability of one number being a part of another Say I have a 4 digit number A such as $1234$. I would like to know what's the probability of it being 'inside' of randomly chosen number B. Example:
number $A = 1234$ is a part of number $B = 5612348$.
Length of $B$ would also be random. I believe the answer is $(n+1-4) : 10^n$, $n$ being the length of $B$, and $4$ is just the length of $A$, because there could be $10^n$ possible $B$ numbers of length $n$, and I can position number $A$ in $n+1-4$ ways. Am I correct?
 A: No. After positioning $A$, you can fill up the other digits to get $B$ in many more ways.
For example: $A=1234$, and $n=5$. Then your formula says that there are $5+1-4=2$ ways to position $A$ (which is correct, since you either start with $1234$ or end with $1234$), but there are more than $2$ numbers out of all $10^5$ that include $A$: $12341, 12342, 12343, ... , 11234, 212234, 31234$ etc.
Now, from this example, the fix seems easy: just multiply by $10^{n-4}$. That is, there are $10$ numbers starting with $1234$, and $10$ numbers ending with $1234$, so that gives you $20$ numbers total, rather than $2$. Or, in general: there are $n-4$ digits left to be filled in after positioning $A$, so there are $10^{n-4}$ ways to do this.
However, what if you have repeating patterns?  For example, what if $A=1111$? Then the $20$ would double-count the $11111$.  Likewise, what if $A=1234$ and $n=8$ ... then you would double-count $12341234$.  And with longer and longer strings, you end up over-counting more and more. So example, $11111111$ will count $1111$ five times.  
I don't think it will be easy to take account all these kinds of over-counting: much depends on the nature of $A$. For example, if $A=3143$, then you have an overlapping $3$ (so, e.g. $3143143$ counts $A$ twice), but with $A=1414$, then $B=14141414$ will count $A$ three times. And depending on the length of $B$, you may not be able to 'fit' overlapping ot repeating $A$'s in there some nice number of times.
So, I think the exact formula may end up being quite, quite nasty. 
