login
A386385
Period-32 block rewriting of A157196 (blocks 11 and 2): for block index i, keep if i mod 32 in {3,4,11,12,15,16,19,20,27,28}, else swap 11<->2.
2
2, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1
OFFSET
0,1
COMMENTS
The runs of '2', and '1,1' are interleaved in the continued fraction expansion of Sum_{k>=0} (-1)^k/(k!)! (A386384).
Parse A157196 into blocks A = 11 and B = 2, and index the blocks i = 0,1,2,.... For each block i, keep it when i mod 32 in {3, 4, 11, 12, 15, 16, 19, 20, 27, 28}; otherwise swap A <-> B (i.e, swap 1,1 <-> 2) at all other i. Finally expand blocks by A -> 1,1 and B -> 2.
We index the blocks starting at i=0. "Keep" residues are {3,4,11,12,15,16,19,20,27,28} (mod 32); at all other residues we swap (11) <-> (2). After that, expand by (11)->1,1 and (2)->2.
Each block is handled independently by its own i mod 32.
EXAMPLE
Starting from A157196 parsed as (11)(2)(11)(11)(2)(11)(2)... = ABAABAB...
i=0: (11), residue 0 not in keep set -> swap to (2) -> output 2.
i=1: (2), residue 1 not in keep set -> swap to (11) -> output 1, 1.
i=2: (11), residue 2 not in keep set -> swap to (2) -> output 2.
i=3: (11), residue 3 is in keep set -> keep (11) -> output 1, 1.
i=4: (2), residue 4 is in keep set -> keep (2) -> output 2.
i=5: (11), residue 5 not in keep set -> swap to (2) -> output 2.
i=6: (2), residue 6 not in keep set -> swap to (11) -> output 1, 1.
Concatenating: 2, 1, 1, 2, 1, 1, 2, 2, 1, 1, ...
PROG
(Python)
def a386385(n):
m=n+1
if m<=0: raise ValueError("n>=0")
M=0x18199818
def run(N, mode):
s=[1, 1]; h=2; p=0; k=0; c=0; y='B'
def g(u):
nonlocal s, h
while len(s)<u:
t=2 if (h&1)==0 else 1
s+= [t]*((s[h-1]*2)//t); h+=1
while k<N:
g(p+2)
if s[p]==2: xb='B'; p+=1
elif p+1<len(s) and s[p]==1 and s[p+1]==1: xb='A'; p+=2
else: g(p+2); continue
y = xb if ((M>>(k&31))&1) else ('A' if xb=='B' else 'B')
c += 2 if y=='A' else 1; k+=1
return c if mode==0 else y
lo, hi=0, m
while lo<hi:
md=(lo+hi)//2
if run(md, 0)>=m: hi=md
else: lo=md+1
return 2 if run(lo, 1)=='B' else 1
CROSSREFS
Sequence in context: A374382 A307017 A220424 * A182907 A334745 A323231
KEYWORD
nonn
AUTHOR
Daniel Hoyt, Aug 17 2025
STATUS
approved