login
The regular paper-folding (or dragon curve) sequence.
11

%I #43 May 10 2023 23:05:20

%S 2,2,1,2,2,1,1,2,2,2,1,1,2,1,1,2,2,2,1,2,2,1,1,1,2,2,1,1,2,1,1,2,2,2,

%T 1,2,2,1,1,2,2,2,1,1,2,1,1,1,2,2,1,2,2,1,1,1,2,2,1,1,2,1,1,2,2,2,1,2,

%U 2,1,1,2,2,2,1,1,2,1,1,2,2,2

%N The regular paper-folding (or dragon curve) sequence.

%H Ivan Panchenko, <a href="/A014710/b014710.txt">Table of n, a(n) for n = 0..10000</a>

%H G. Melançon, <a href="https://www.researchgate.net/publication/322200645_MapleTech_Volume_4_no_1_Spring_1997">Factorizing infinite words using Maple</a>, MapleTech journal, vol. 4, no. 1, 1997, pp. 34-42, esp. p. 36.

%H <a href="/index/Fo#fold">Index entries for sequences obtained by enumerating foldings</a>

%F Set a=2, b=1, S(0)=a, S(n+1) = S(n)aF(S(n)), where F(x) reverses x and then interchanges a and b; sequence is limit S(infinity).

%F a(4*n) = 2, a(4*n+2) = 1, a(2*n+1) = a(n).

%t Nest[Append[#1, If[EvenQ[#2], 2 - BitAnd[1, #2/2], #1[[Ceiling[#2/2]]]]] & @@ {#, Length@ #} &, {2}, 105] (* _Michael De Vlieger_, Apr 08 2021 *)

%o (PARI) a(n)=if(n%2==0, 2-bitand(1,n\2), a(n\2) );

%o for(n=0,122,print1(a(n),", "))

%o (Python)

%o def A014710(n):

%o s = bin(n+1)[2:]

%o m = len(s)

%o i = s[::-1].find('1')

%o return 2-int(s[m-i-2]) if m-i-2 >= 0 else 2 # _Chai Wah Wu_, Apr 08 2021

%Y See A014577 for more references and more terms.

%Y The following are all essentially the same sequence: A014577, A014707, A014709, A014710, A034947, A038189, A082410. - _N. J. A. Sloane_, Jul 27 2012

%K nonn

%O 0,1

%A _N. J. A. Sloane_.