%I #75 Jan 16 2023 08:17:51
%S 1,1,0,1,1,0,1,0,0,0,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,1,0,1,1,1,
%T 1,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,1,1,1,1,
%U 1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0
%N Left(0)/right(1) turning sequence needed to traverse the Stern-Brocot tree (A007305, A047679) from the root down to e (A001113).
%C The sequence has the following regular pattern: 1 0{0} 1 0 1{2} 0 1 0{4} 1 0 1{6} 0 1 0{8} ... where {r} indicates that the preceding term is repeated r times.
%C Run lengths of this sequence (A003417) are the coefficients of the continued fraction for e.
%C The positions of zeros and ones are given by A358510 and A358511, respectively. - _Paolo Xausa_, Nov 20 2022
%D R. L. Graham, D. E. Knuth and O. Patashnik, Concrete Mathematics, 2nd Edition, Addison-Wesley, 1989, p. 115-123.
%H Michael De Vlieger, <a href="/A342991/b342991.txt">Table of n, a(n) for n = 1..10000</a>
%H Michael De Vlieger, <a href="/A342991/a342991.png">2^11 X 2^11 bitmap of a(n)</a>, n = 1..2^22, where white represents 0 and black represents 1.
%H Michael De Vlieger, <a href="/A342991/a342991_1.png">Binary tree of a(n)</a>, n = 1..2^14-1, where dark blue represents 0 and red represents 1.
%F The sequence begins with
%F floor(e / 1) = A003417(1) ones, followed by
%F floor(1 / (e mod 1)) = A003417(2) zeros, followed by
%F floor((e mod 1) / (1 mod (e mod 1))) = A003417(3) ones, followed by
%F floor((1 mod (e mod 1)) / ((e mod 1) mod (1 mod (e mod 1)))) = A003417(4) zeros
%F ...
%F From _Paolo Xausa_, Nov 20 2022: (Start)
%F a(A358510(n)) = 0.
%F a(A358511(n)) = 1.
%F Limit_{n->oo} (1/n)*Sum_{i=1..n} a(i) = 1/2. (End)
%e In the initial portion of the Stern-Brocot tree shown below, the arrows indicate the traversing route.
%e 1/1
%e |
%e .----------------->-----. Right (1)
%e | |
%e 1/2 2/1
%e | |
%e .-----------. .-------->--. Right (1)
%e | | | |
%e 1/3 2/3 3/2 3/1
%e | | | |
%e .-----. .-----. .-----. .-<---. Left (0)
%e | | | | | | | |
%e 1/4 2/5 3/5 3/4 4/3 5/3 5/2 4/1
%e ...
%e The first terms of the sequence are therefore 1, 1, 0.
%t (* Generate up to 2^22 terms of this sequence from the 2^11 X 2^11 bitmap *)
%t With[{rows = 12}, ImageData[Import["https://oeis.org/A342991/a342991.png"]][[1 ;; rows]] /. {0. -> 1, 1. -> 0} // Flatten] (* _Michael De Vlieger_, Nov 04 2022 *)
%t A342991[i_]:=Flatten[Array[{1, PadRight[{}, 4#], 1, 0, PadRight[{}, 2+4#, 1], 0}&, i, 0]]; (* Each iteration adds six runs of values *)
%t A342991[10] (* _Paolo Xausa_, Nov 20 2022 *)
%o (Python)
%o from itertools import count, islice
%o def A342991_gen(): # generator of terms
%o a = 0
%o yield from (1,1)
%o for n in count(2):
%o q, r = divmod(n,3)
%o yield from (a,)*(1 if r else q<<1)
%o a = 1-a
%o A342991_list = list(islice(A342991_gen(),40)) # _Chai Wah Wu_, Nov 04 2022
%o (PARI)
%o A342991(iter) = concat(vector(iter,i,concat([1,vector((i-1)<<2),1,0,vector(2+(i-1)<<2,x,1),0]))); \\ Each iteration adds six runs of values
%o A342991(10) \\ _Paolo Xausa_, Nov 24 2022
%o (PARI) a(n) = my(r,s=sqrtint(n-1,&r)); bitand(s + (r<s-1 || r==s), 1); \\ _Kevin Ryde_, Nov 24 2022
%Y Cf. A001113, A003417, A007305, A047679, A119014, A119015.
%Y Cf. A358510, A358511.
%K nonn,easy
%O 1
%A _Paolo Xausa_, Jul 21 2021