Error in fun problem of series and the binary representation of n The problem is as follows:
Let $a_n = :$ number of digits of $n$ in binary notation, and $$A_n = \frac{1}{n} \sum_{k=1}^{n} (-1)^{a_n} $$.
Show that $\limsup A_n = 1/3$.
From previous questions, I have asserted that
$$a_n =
\left\{
 \begin{array}{111111}
  1  & \mbox{if } n = {1}\\
  2 & \mbox{if } n = {2,3}\\
  3 & \mbox{if } n = {4,...,7} \\
  4 & \mbox{if } n = {8,...,15} \\
  ...\\
  k+1 & \mbox{if } n = {2^k,...,(2^{k+1} - 1)} 
 \end{array}
\right.$$
and that $A_n$ increases for $k+1$ even and decreases for $k+1$ odd. Trying to solve the problem at hand, I wrote:
The terms of $a_n$ equal to a particular $k+1$ are those of order $2^k$ to $2^{k+1}$. Hence there are $2^{k+1} - 2^k = 2^k$ such terms.
We will call upper peaks all terms $A_i$ such that $A_{i-1} \leq A_i \geq A_{i+1}$. This means that $a_i$ is even, while $a_{i+1}$ is odd, which, from the definition of $a_n$ happens if $i = 2^{k+1} - 1$, for some k odd. Then,
$$A_i = \frac{1}{2^{k+1} - 1} \sum_{k=1}^{n} (-1)^a_n$$
Explicitly computing the sum, as there are $2^{k+1} - 2^k = 2^k$ terms equal to a particular $k+1$,
$$A_i = \frac{1}{2^{k+1} - 1} (-1 +1 +1 -... +1)= \frac{1}{2^{k+1} - 1} (-2^0 + 2^1 - 2^2...+2^{k})$$
Notice that we can pair every two terms of the sum into a pair of the form $2^{k+1} - 2^k = 2^k$. Hence,
$$A_i = \frac{1}{2^{k+1} - 1} (2^0 + 2^2 + ... + 2^{k-1})$$
Now the sum is but a simple geometric progression, of ratio $2^2/2^0 = 2^2$, and with $k-1-0+1 = k$ terms. By the formula of the sums of geometric progressions,
$$A_i = \frac{1}{2^{k+1} - 1} \times  \frac{1 - {2^{2}}^{k/2}}{1 - 2^2} = \frac{1 - 2^k}{3 - 3*2^{k+1}} $$
The issue here is that this $A_i$ has limit of $1/6$, and not $1/3$, as desired.
Hope you can help me, I found this a pretty fun problem to try and solve. 

In the last line, instead of
$$A_i = \frac{1}{2^{k+1} - 1} \times  \frac{1 - {2^{2}}^{k/2}}{1 - 2^2} $$
it should be
$$A_i = \frac{1}{2^{k+1} - 1} \times  \frac{1 - 2^{k+1}}{1 - 2^2}=\frac13$$
