Assuming that $i \geq 0$, let $p\_i$ denote an $i$-th prime: $p\_0 = 2, p\_1 = 3, \ldots$ Then $b\_i$ denotes the second-to-last bit of $p\_i$, i.e. $b\_i = \left\lfloor p\_i/2 \right\rfloor \bmod 2.$


The sequences $B\_0$ and $B\_1$ are constructed by the following algorithm: if $b\_i$ is equal to $i \bmod 2$, append $b\_i$ to $B\_0$; otherwise (i.e. if $b\_i$ is not equal to $i \bmod 2$), append $b\_i$ to $B\_1$. Thus $$\begin{array}{l}
B\_0 = 
1010101101010101010101101010101010011001001111001101001011001010\ldots,\\
B\_1 = 
1101010101011001011010101100101010101010010101011101010101010101\ldots
\end{array}$$


Basically, both of these sequences are $\ldots1010\ldots$, slightly interspersed with runs of two or more identical bits. For example, the first $10^6$ bits of $B\_1$ do not even contain ten consecutive zeros. What is the explanation of this phenomenon?



How to explain a particular property of the second-to-last bits of primes?
I think the phenomena you observe are explained more by the way you construct $B\_0$ and $B\_1$ than by the properties of primes (though properties of primes seem to play a role). If we suppose instead that $b\_i$ were random, obtained by a coin flip, it's easy to see that for each bit of $B\_0$ or $B\_1$, the probability that the next bit is the same is $\frac{1}{3}$, and the probability that the next bit is different is $2/3$.


Indeed, say $b\_i \equiv i \mod 2$ for some $i$, so at time $i$ we have just added $b\_i$ to $B\_0$.


Then if the next $k-1$ bits are not congruent to their position mod $2$, followed by the $k$th bit congruent to its position, $i+k$, mod $2$, we next append the bit $i+k \mod 2$ to $B\_0$. This occurs with probability $\frac{1}{2^k}$, and in each sequence this occurs for exactly one value of $k$.


So we get a different bit with probability $\frac{1}{2} + \frac{1}{2^3} + \frac{1}{2^5} + \dots = \frac{2}{3}$, and the same bit with probability $\frac{1}{2^2} + \frac{1}{2^4} + \frac{1}{2^6} + \dots = \frac{1}{3}$. The $B\_1$ case is identical.


So the probability of getting $10$ consecutive zeroes starting at any given point is $\frac{1}{2} \cdot \frac{1}{3^9}$. However, the length of time we expect to take before seeing the first run of $10$ consecutive zeroes is a little longer than the inverse of that, $3^{10}-1=59048$, by a classical argument.


So we waited about 17 times longer than one would expect to find a run of ten zeroes. (But you had 4 choices to pick to find such a long run without zeroes). That's not completely surprising, but it's a lot less strange than in the naive random model, where the expected wait time is $2^{11}-1$, so you would have waited about $489$ times longer than expected.




---


More generally, if we replace $b\_i$ with a Markov chain with probability of taking the same value on adjacent steps $p$, then the probability that $B\_0$ takes the same value on adjacent steps should be $$p^2 + p^2(1-p)^2 + p^2 (1-p)^4 + \dots = \frac{ p^2}{ 1- (1-p)^2} = \frac{p^2 }{ 2p -p^2} = \frac{p}{ 2-p}$$ since to get two of the same bit in $B\_0$, $b\_i$ must be same-same or same-different-different-same or same-different-different-different-different-same.


To explain $\frac{ p}{2-p} = \frac{1}{2} - .28 = .22$ as in dvitek's analysis, we need $p= \frac{2}{ 1/.22 +1} =.361$, i.e. there is a discrepancy of about $.14$ to explain in the more natural statistic of how often two adjacent primes have distinct second-to-last bits.


