<!-- There are quite a few simple and interesting properties about these sequences of 1's and 2's. -->

Let $2^m$ be the largest power of $2$ not greater than $n$, a positive integer. <!-- i.e., $n=2^m+n_r$ for some $n_r$ such that $0\le n_r\lt 2^m$ --> 

As mentioned in the question, if we repeatedly replace each term $\cdot$ with $\lfloor \frac \cdot2 \rfloor$, $\lceil \frac \cdot2 \rceil$, we will change $[n]$ to a sequence of $2^m$ terms, each of which is either 1 or 2. 

Let that sequence be $S(n)=[S_0, S_1, S_2,\cdots, S_{2^m-1}]$. We have $S_0=1$ since $S_0=\lfloor\frac n{2^m}\rfloor$.

**Formula for the general term.** For all $i$, we have $S_i=1$ if $n-2^m \le r\!c_m(i)$ and $S_i=2$ otherwise. 

Here $r\!c_m(i)$ is the **r**everse of the **c**omplement of $m$-bit binary representation of $i$, i.e, if the binary representation of $i$ is $i_{m-1}i_{m-2}\cdots i_1i_0$, <!-- with possible leading zeros! -->  <!-- i=\Sigma_{j=0}^{m-1}i_j2^j--> then the binary representation of $r\!c_m(i)$ is $(1-i_0)(1-i_1)\cdots(1-i_{m-2})(1-i_{m-1})$ <!--\Sigma_{j=0}^{m-1}(1-i_{m-1-j})2^j-->. 

<!-- The formula becomes tautological once we have understood how we arrive at $S_i$. --> 

For example, we have $$[r\!c_3(0), r\!c_3(1), r\!c_3(2), r\!c_3(3), r\!c_3(4), r\!c_3(5), r\!c_3(6), r\!c_3(7)]=[7, 3, 5, 1, 6, 2, 4, 0].$$ Since $12 = 2^3 + 4$, comparing 4 with each term $r\!c_3(\cdot)$, we obtain,

$$S(12) = [1,2,1,2,1,2,1,2].$$

**Proof**: We do induction on $m$, which is $\lfloor\log_2(n)\rfloor$.

The base case is when $m=0$, i.e., $n=1$. The sequence $S(1)=[1]$. The formula holds.

Suppose the formula is true for $m$, i.e, for all $n$ and $i$ such that $2^m\le n\lt2^{m+1}$, $S(n)_i=1$ iff $n-2^m\le r\!c_m(i)$.

Now consider the case of $m+1$. 

Suppose $2^{m+1}\le n\lt2^{m+2}$. By definition, we have $S(n)=[S(\lfloor \frac n2 \rfloor), S(\lceil \frac n2 \rceil)]$, where we abuse the bracket so that $[\cdot, \cdot]$ means the concatenation of the two sequence, i.e., for example, $[[1,2,2,1], [1,1,1,2]]=[1,2,2,1,1,1,1,2]$. Since $2^m\le\lfloor \frac n2 \rfloor, \lceil \frac n2 \rceil\lt2^{m+1}$, we can apply the induction hypothesis to $S(\lfloor \frac n2 \rfloor)$ and $S(\lceil \frac n2 \rceil)$.

What is $S(n)_i$? There are two cases.

 - $0\le i\lt 2^m$. Then $S(n)_i = S(\lfloor \frac n2 \rfloor)_i$. So $$\begin{align}
S(n)_i=1&\Leftrightarrow S(\lfloor \frac n2 \rfloor)_i=1
\\&\Leftrightarrow \lfloor \frac n2 \rfloor-2^m\le r\!c_m(i)
\\&\Leftrightarrow 2(\lfloor \frac n2 \rfloor-2^m)\le 2r\!c_m(i)
\\&\Leftrightarrow n -2^{m+1}\le r\!c_{m+1}(i)
\end{align}$$
where the last equivalence comes from the fact $2\lfloor \frac n2 \rfloor$ equals $n$ or $n-1$ and $2r\!c_m(i)=r\!c_{m+1}(i)-1$. 
 - $2^m\le i\lt2^{m+1}$. Then $S(n)_i = S(\lceil \frac n2 \rceil)_{i-2^m}$. So
$$\begin{align}
S(n)_i=1&\Leftrightarrow S(\lceil \frac n2 \rceil)_{i-2^m}=1
\\&\Leftrightarrow \lceil \frac n2 \rceil-2^m\le r\!c_m({i-2^m})
\\&\Leftrightarrow 2(\lceil \frac n2 \rceil-2^m)\le 2r\!c_m({i-2^m})
\\&\Leftrightarrow n -2^{m+1}\le r\!c_{m+1}(i)
\end{align}$$
where the last equivalence comes from the fact $2\lceil \frac n2 \rceil$ equals $n$ or $n+1$ and $2r\!c_m({i-2^m})=r\!c_{m+1}(i)$. 

------

Once we know the above formula, we have the following simple iterative algorithm, which is a direct translation of the formula above.

Input: a positive integer $n$.  
Output: the wanted sequence  
Procedure:
  
 1. Compute integer $m$ and $n_r$ such that $n=2^m+n_r$, where $0\le n_r\lt 2^m$.
  
 2. loop $i$ through 0 to $2^m-1$.
    
    1. Compute the reverse of the $m$-bit complement of $i$, $rc_m(i)$.
    2. Output $1$ if $n_r \le rc_m(i)$. Output 2 otherwise.

Note that for $i$ between $0$ and $2^m-1$, the function $i\to rc(i)$ is a bijective function, since both complement and reverse are bijective. We could optimize the algorithm by devising a way to compute the binary representation of $rc(i+1)$ directly from the binary representation of $rc(i)$. That will make the algorithm even more "iterative" as well. We can also precompute the sequence $r\!c_m(0), r\!c_m(1), \cdots, r\!c_m(2^m-1)$ by taking advantage of its iterative pattern, for example, with $m=4$,
$$15, \underbrace{7}_{[15]-8}, \underbrace{11, 3}_{[15,7]-4}, \underbrace{13, 5, 9, 1}_{[15, 7, 11, 3]-2}, \underbrace{14, 6, 10, 2, 12, 4, 8, 2}_{[15, 7, 11, 3, 13, 5, 11, 1]-1}.$$ 

---

**A simple exercise.** Find the similar formula for the general sequence $S_k(n)$, which is obtained by modifying the sequence $[n]$ for $k$ rounds, where every term $\cdot$ in the sequence is replaced by two terms, $\lfloor \frac \cdot2 \rfloor$ and $\lceil \frac \cdot2 \rceil$ in each round. $n$ and $k$ can be any nonnegative integer. For example, $S_2(10)=[2, 3, 2, 3]$ and $S_4(10)=[0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1]$.

<!-- **Answer**
For all $k$, $$(S_k(n))_i-(n//2^{k})=
\begin{cases}0\quad\text{if } n\%2^{k}\le rc_k(i),\\1\quad\text{otherwise.}\end{cases}$$   

where $n//2^k$ and $n\%2^k$ are the integer quotient and the remainder of $n$ divided by $2^k$, respectively, as in Python notation.
-->


<!--  HalfANumberRepeatedly_cs123445.java.base64
aW1wb3J0IGphdmEudXRpbC5BcnJheXM7Y2xhc3MgSGFsZkFOdW1iZXJSZXBlYXRlZGx5X2NzMTIzNDQ1e3B1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3Mpe2ZvcihpbnQg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W50IG49KDE8PGV4cCkrMTtuPDE8PChleHArMSk7bisrKXtpbnRbXWN1cnJlbnQ9c2VxdWVuY2Uobik7Zm9yKGludCBrPTA7azwxPDxleHA7aysrKXtpZihjdXJyZW50W2tdPHByZXZpb3VzW2tdKXtTeXN0ZW0ub3V0LnByaW50bG4oIldyb25nIG46IituK0FycmF5cy50b1N0cmluZyhwcmV2aW91cykrQXJyYXlzLnRvU3RyaW5nKHByZXZpb3VzKSsiIHByZXZpb3VzWyIraysiXT0iK3ByZXZpb3VzW2tdKyIgY3VycmVudFsiK2srIl09IitjdXJyZW50W2tdKTt9aWYoY3VycmVudFtrXT5wcmV2aW91c1trXSl7U3lzdGVtLm91dC5wcmludGxuKChrKzEpKyIgIik7fX1wcmV2aW91cz1jdXJyZW50O31TeXN0ZW0ub3V0LnByaW50bG4oMSsiICIpO319c3RhdGljIHZvaWQgdGVzdEdyZWF0ZXJQb3NpdGlvblBhdHRlcm4oKXtpbnRbXXByZXZpb3VzR3JlYXRlclBvcz17MX07Zm9yKGludCBleHA9MTtleHA8NztleHArKyl7U3lzdGVtLm91dC5wcmludGxuKCk7aW50W11ncmVhdGVyUG9zPW5ldyBpbnRbMTw8ZXhwXTtncmVhdGVyUG9zW2dyZWF0ZXJQb3MubGVuZ3RoLTFdPTE7aW50W11wcmV2aW91cz1zZXF1ZW5jZSgxPDxleHApO2ZvcihpbnQgbj0oMTw8ZXhwKSsxO248MTw8KGV4cCsxKTtuKyspe2ludFtdY3VycmVudD1zZXF1ZW5jZShuKTtmb3IoaW50IGs9MDtrPDE8PGV4cDtrKyspe2lmKGN1cnJlbnRba108cHJldmlvdXNba10pe1N5c3RlbS5vdXQucHJpbnRsbigiV3JvbmcgbjoiK24rIiBrOiIraytBcnJheXMudG9TdHJpbmcocHJldmlvdXMpK0FycmF5cy50b1N0cmluZyhwcmV2aW91cykrIiBwcmV2aW91c1siK2srIl09IitwcmV2aW91c1trXSsiIGN1cnJlbnRbIitrKyJdPSIrY3VycmVudFt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