The problem can be attacked by using Inclusion-Exclusion, with Stars and Bars used internally. First, briefly see this self-answer question which uses the methodology to attack a similar question, and also provides links to other problems that were conquered by the same methodology.
I am not suggesting that you read the self-answer question in detail. Instead, I am suggesting that you merely browse the question to get the idea of what is going on.
For simplicity, I will assume that the leftmost digit of the
$~n$-digit number is permitted to equal $~0.$
Let $~n~$ be some fixed positive integer $~\geq 4.$
Let $~N~$ denote the number of such $~n$-digit numbers that do not contain any occurrence of $~3~$ consecutive 6's.
Then, since the desired probability is
$$1 - \frac{N}{10^n},$$
the entire problem is reduced to provided a closed form formula for $~N,~$ as a function of $~n.$
Let $~S~$ denote the collection of all possible $~n$-digit numbers.
For $~k \in \{1,2,\cdots,n-2\},~$ let $~S_k~$ denote the subset of $~S~$ that specifically contains $~3~$ consecutive 6's, starting in position $~k.~$ Here, I am reading the positions from left to right.
For example, any element in $~S_1~$ will be an $~n$-digit number that contains $~3~$ consecutive 6's in the leftmost $~3~$ digit positions, and may or may not also contain one or more other occurrences of $~3~$ consecutive 6's.
Then, the desired computation is
$$N = | ~S ~| - | ~S_1 \cup S_2 \cup \cdots \cup S_{n-2} ~|. \tag1 $$
$\underline{\text{General Considerations For Inclusion-Exclusion}}$
Let $~T_0~$ denote $~| ~S ~| \implies $
$$T_0 = 10^n.~$$
Let $~T_1~$ denote $~\displaystyle \sum_{1 \leq i_1 \leq n-2} | ~S_{i_1} ~|.$
That is, $~T_1~$ represents the sum of $~\displaystyle \binom{n-2}{1} ~$ terms.
By considerations of symmetry,
$$T_1 = (n-2) \times 10^{n-3}.$$
For $~r \in \{2,3,\cdots,n-2\},~$
let $~T_r~$ denote $~\displaystyle \sum_{1 \leq i_1 < i_2 < \cdots < i_r \leq n-2} | ~S_{i_1} \cap S_{i_2} \cap \cdots \cap S_{i_r} ~|.$
That is, $~T_r~$ represents the sum of $~\displaystyle \binom{n-2}{r} ~$ terms.
Then, in accordance with Inclusion-Exclusion theory,
$$N = \sum_{r = 0}^{n-2} (-1)^r T_r.$$
However, considerations of symmetry, that were useful when computing $~T_1,~$ break down when computing $~T_r ~: ~r \geq 2.$
So, the entire problem is reduced to using Stars and Bars internally to provide a closed form formula for $~T_r ~: ~r \geq 2.$
The remainder of this answer will :
Analytically develop a helper function $~f(n,r,w,o)~$ and explain how this function may be used to compute $~T_r ~: ~r \geq 2.$
In this section, the variables $~n,r,w,o~$ will be specified and discussed.
Provide upper and lower bounds on the variables $~n,r,w,o~$ where appropriate.
Summarize all of the results, with a (very convoluted) closed form formula.
$\underline{\text{Helper Function} ~f(n,r,w,o)}$
This section will partition the $~\displaystyle \binom{n-2}{r}~$ intersections represented by the term $~T_r ~: ~r \geq 2~$ into categories. The purpose of the function $~f(n,r,w,o)~$ is to enumerate how many $~n$-digit numbers pertain to each category.
At the start of this section, for illustrative purposes, I will asssume that $~n = 20,~$ and $~r = 5.~$ Then, later in this section, I will discuss the general case of $~n \geq 4, ~r \in \{2,3,\cdots, n-2\}.$
Consider the following tableau:
i_1 - - i_2 - - i_3 - - i_4 - - i_5 - - - - -
In the above tableau, the positions of $~i_1, \cdots, i_5,~$ are $~1, 4, 7, 10, 13,~$ respectively. This represents the intersection of the subsets $~S_{1} \cap S_4 \cap S_7 \cap S_{10} \cap S_{13},~$ which represents one of the intersections pertinent to the computation of $~T_5.$
The $~5~$ subsets involved create $~(5 +1)~$ islands between the subsets. Reading the islands from left to right, let $~x_1, \cdots, x_6,~$ denote the respective sizes of these islands. Then, you have that the ordered $~6$-tuplet $~(x_1, \cdots, x_6) = (0,2,2,2,2,5). ~$ Note that since $~5~$ of the $~(20-2)~$ digit positions are taken by the positions of $~i_1, \cdots, i_5,~$ you must have that $~x_1 + \cdots + x_6 = (20 - 2) - 5 = 13.$
Then, the number of distinct ordered $~6$-tuplets $~(x_1,\cdots,x_6)~$ equals the number of solutions to
- $x_1 + \cdots + x_6 = 13.$
- $x_1, \cdots, x_6 \in \Bbb{Z_{\geq 0}}.$
By basic Stars and Bars theory, the number of solutions is
$\displaystyle \binom{13 + [6-1]}{6-1} = \binom{18}{5}.$
So, with $~n = 20, ~$ each possible intersection of $~5~$ subsets that is pertinent to the computation of $~T_5~$ is uniquely represented by one of the satisfying ordered $~6$-tuplets $~(x_1, \cdots,x_6).$
Speaking more generally, what is needed is some method of partitioning the $~\displaystyle \binom{n-2}{r} ~$ pertinent intersections into mutually exclusive categories, where each category may be analytically diagnosed.
To do this, the variables $~x_1~$ and $x_{r+1}~$ may be ignored. For the other $~(r - 1)~$ variables, I am going to let $~w~$ denote the number of such variables that are $~\geq 2~$ and let $~o~$ denote the number of such variables that are $~= 1.~$ Then, it is to be understood that exactly $~(r - 1) - w - o~$ of these variables are equal to $~0.$
So, the categories will be based on the values of the variables $~n,r,w,o.$
The helper function $~f(n,r,w,o)~$ will enumerate how many $~n$-digit numbers are possible that pertain to the category represented by the specific values of the variables $~n, ~r, ~w,~$ and $~o.~$ The following procedure will be used to compute $~f(n,r,w,o):$
Step 1
Enumerate the number of possible ways that you can choose $~w~$ variables from $~x_2, \cdots, x_r,~$ and then choose $~o~$ variables from the remaining $~(r-1-w)~$ variables.
Step2
Assume that (reading the variables from left to right, starting with variable $~x_2$) that the first $~w~$ variables are $~\geq 2,~$ and the next $~o~$ variables are $~= 1.~$ Then, under this assumption, identify the number of intersections that correspond to this assumption.
The intention is that the product of the computations in Step 1 and Step 2 will determine how many of the $~\displaystyle \binom{n-2}{r}~$ intersections correspond to the category represented by the specific set of values for $~n, ~r, ~w, ~$ and $~o.$
Step 3
For any intersection of $~r~$ of the subsets of $~S_1, S_2, \cdots, S_{n-2},~$ that pertains to the category represented by the specific values of the variables $~n, ~r, ~w, ~$ and $~o, ~$ compute the number of $~n$-digit numbers that are represented by this intersection.
Step 4
Take the combined product of the computations in each of Steps 1 through 3. The result will be the function $~f(n,r,w,o).$
The Step 1 computation is:
$$\binom{r-1}{w} \times \binom{r-1-w}{o}.$$
The analysis for the Step 2 computation requires discussion. In the basic Stars and Bars enumeration, you start with $~(r + 1)~$ variables, whose sum is $~(n-2 - r).~$ Eliminating the $~(r - 1 - w - o) ~$ variables that are $~= 0~$ reduces the number of variables to $~(2 + w + o),~$ and leaves the sum of $~(n - 2 - r)~$ unchanged.
Then, eliminating the $~o~$ variables that are $~= 1~$ reduces the number of variables to $~(w + 2),~$ and reduces the sum to $~(n - 2 - r - o).$ So, at this point, the Step 2 computation is represented by the number of solutions to
- $x_1 + y_2 + \cdots + y_{w+1} + x_{r+1} = (n - 2 - r - o).$
- $x_1, x_{r+1} \in \Bbb{Z_{\geq 0}}.$
- $y_2, \cdots, y_{w+1} \in \Bbb{Z_{\geq 2}}.$
Now employ the further change of variables $~z_i = y_i - 2 ~: ~i \in \{2,3,\cdots,w+1\}.$
This leaves the number of variables unchanged at $~(w + 2)~$ and reduces the sum to $~(n - 2 - r - 2w - o).$ Therefore, the Step 2 computation is represented by the number of solutions to
- $x_1 + z_2 + \cdots + z_{w+1} + x_{r+1} = (n - 2 - r - 2w - o).$
- $x_1, x_{r+1} \in \Bbb{Z_{\geq 0}}.$
- $z_2, \cdots, z_{w+1} \in \Bbb{Z_{\geq 0}}.$
By basic Stars and Bars theory, the Step 2 computation is therefore
$$\displaystyle \binom{[n - 2 - r - 2w - o] + [w + 1]}{w + 1} = \binom{n - 1 - r - w - o}{w+1}.$$
The analysis for the Step 3 computation also requires discussion. First, suppose that $~w = (r-1),~$ which implies that $~o = 0, ~(r - 1 - w - o) = 0. ~$ Then, each pair of subsets $~S_i~$ and $~S_{i+1},~$ has at least two digit positions between them. Therefore, you can regard this pair of subsets as fully uncompressed. Then, of the $~n~$ digit positions, exactly $~(3r)~$ of them are forced to equal $~6.~$
Now, assume instead that there are $~o~$ of the $~(r - 1) ~$ variables that are $~= 1.~$ Then, you have $~o~$ partially compressed pairs of subsets that (together) use $~5~$ digit positions instead of $~6~$ digit positions. This implies that you now have $~(3r - o)~$ digit positions that are forced to equal $~6.~$
Now, further assume that you have some fully compressed pairs of subsets because $~(r - 1 - w - o) \neq 0.~$ Similar to the analysis in the previous paragraph, this implies that exactly $~[ ~(3r - o) - 2(r - 1 - w - o) ~] = [ ~r + 2 + 2w + o ~] ~$ of the digit positions are forced to equal $~6.~$
So, with respect to the $~n~$ digit positions, you have exactly
Therefore, the computation for Step 3 is
$$10^{ ~[n - 2 - r - 2w - o] ~}.$$
Therefore, by Step 4,
$$f(n,r,w,o) = \binom{r-1}{w} \times \binom{r-1-w}{o} \times \binom{n - 1 - r - w - o}{w+1}$$
$$\times 10^{ ~[n - 2 - r - 2w - o] ~}.$$
The next section in this answer will specify the allowable ranges for each of the variables $~n, ~r, ~w,~$ and $~o.$
So, by the analysis in this section, for this specific value of $~n~$ and $~r,~$
$$T_r = \sum_{w ~\text{in range}} \left\{ \sum_{o ~\text{in range}} ~[ ~f(n,r,w,o ~] \right\}.$$
$\underline{\text{Lower And Upper Bounds For} ~n, ~r, ~w, ~\text{And} ~o}$
You have that
$\displaystyle f(n,r,w,o) = \binom{r-1}{w} \times \binom{r-1-w}{o} \times \binom{n - 1 - r - w - o}{w+1}$
$\displaystyle \times 10^{ ~[n - 2 - r - 2w - o] ~}.$
$n \in \Bbb{Z_{\geq 4}}.$
With respect to the appropriate range of $~r,~$ so that $~f(n,r,w,o)~$ may be applied, the lower bound for $~r~$ is $~2 \leq r.$
My experience with math problems of this nature has taught me that the easiest way to compute the upper bound for $~r,~$ and the lower/upper bounds for $~w~$ and $~o,~$ is to consider that for any pertinent expression of the form $~\displaystyle \binom{p}{q} ~: ~p,q \in \Bbb{Z},~$ you must have $~q \geq 0, ~p \geq q. ~$ Further, the expression $~[ ~n - 2 - r - 2w - o ~] ~$ must be a non-negative integer.
Therefore, the first take on the bounding constraints is that
- $0 \leq w \leq r-1.$
- $0 \leq o \leq r-1-w.$
- $n - 2 - r - 2w - o \geq 0.$
The upper bound for $~r~$ is achieved when $~0 = w,o.$ So, the range of $~r~$ is
$$r \in \Bbb{Z}, ~2 \leq r \leq n-2.$$
Both of the variables $~w~$ and $~o~$ can be as small as $~0,~$ since this merely represents having the intersection $~\{ ~S_{i_1} \cap S_{i_2} \cap \cdots \cap S_{i_r} ~\}~$ fully compressed.
The upper bound for $~w~$ may be determined by setting $~o = 0.~$
Therefore, the range of $~w~$ is
$$w \in \Bbb{Z}, ~0 \leq w \leq \min\left\{ ~r-1, ~\left\lfloor ~\frac{n-2-r}{2} ~\right\rfloor ~\right\}.$$
Similarly, the range of $~o~$ is
$$o \in \Bbb{Z}, ~0 \leq o \leq \min\left\{ ~r-1-w, ~n - 2 - r - 2w ~\right\}.$$
$\underline{\text{Closed Form Formula For The Problem}}$
It is assumed that $~n~$ is some fixed positive integer $~\geq 4,~$ and that the leftmost digit of an $~n$-digit number is permitted to equal $~0.$
The desired computation is
$$1 - \dfrac{N}{10^n} ~: ~N = \sum_{r=0}^{n-2} (-1)^r T_r.$$
$$T_0 = 10^n.$$
$$T_1 = (n - 2) \times 10^{n-3}.$$
The remainder of this section assumes that $~r \in \Bbb{Z}, ~2 \leq r \leq n-2.$
The helper function $~f(n,r,w,o)~$is defined as
$$f(n,r,w,o) = \binom{r-1}{w} \times \binom{r-1-w}{o} \times \binom{n - 1 - r - w - o}{w+1}$$
$$\times 10^{ ~[n - 2 - r - 2w - o] ~}.$$
The ranges for the variables $~w~$ and $~o~$ are
$$w \in \Bbb{Z}, ~0 \leq w \leq \min\left\{ ~r-1, ~\left\lfloor ~\frac{n-2-r}{2} ~\right\rfloor ~\right\}.$$
$$o \in \Bbb{Z}, ~0 \leq o \leq \min\left\{ ~r-1-w, ~n - 2 - r - 2w ~\right\}.$$
Then
$$T_r = \sum_{w ~\text{in range}} \left\{ \sum_{o ~\text{in range}} ~[ ~f(n,r,w,o ~] \right\}.$$