How to constructing a binary regular expression for 8 bits, where "1 1 1" occurs twice in any configuration and the other two bits can be whatever?

79 Views Asked by At

I'm trying to make a regex for my language with alphabet $\Sigma = \{"0","1"\}$ that captures any 8 bits where the sequence "1 1 1" occurs twice without overlap. These two sequences can be adjacent, but don't have to be. The remaining two bits can be either "0" or "1". It doesn't matter what they are, but it needs to be possible for them to be anything.

Mainly the length limitation is what I'm struggling with. If the length was irrelevant it could have easily been $$ \Sigma^* \circ (111) \circ \Sigma^* \circ (111) \circ \Sigma^* $$ since $\Sigma^*$ includes empty. However, the size of each realization $\Sigma^*$ depends on the realizations of the others. I have no clue how to capture this in the expression.

Any help would be greatly appreciated!

1

There are 1 best solutions below

1
On

As $111$ is together, we can consider this as $4$ characters of two {111} and other two as $1$ or $0$.

If other two are both $0$, we have $4 \choose 2$ ways to place two {111} them in $4$ spaces and other two places are then taken by $0$.

If other two characters are both $1$ then there is only one way to arrange as all are $1$.

If other two characters are one $1$ and one $0$, we again have $4 \choose 2$ ways to arrange. If you think of total arrangements, it is $12$ but half of them are duplicates.

So in total, we have $13$ distinct arrangements.