from copy import copy
from time import sleep #for suspenseful purposes
from itertools import zip_longest,starmap #gotta have long enough zippers and locatory mechanisms when your robes are as spacefaring as these
strist=lambda col=0: lambda l: '['+''.join(map(('░▒▓█' if col else '░█').__getitem__,l))+']' #string-list portcreateaure(portmanteau-creature)
dbg=lambda x,*a: (x,print('\n'.join(map(strist(),a+(x,)))))[0]
X=lambda f: (lambda g: g(g))(lambda g: f(lambda: g(g))) #much better than the Y combinator whatever that thing is
watch=lambda x: bool(x and x[0]) #they watch
bite=lambda x: bool(x and x.pop(0)) #bites you tee hee

"""help me i have forgotten how to count
i am trying to count in binary but all i get is this weird sequence
my binary counter is developing dendritic tendrils everywhere
why are the least-place-value bits beckoning to me so ominously... whatever could be their significance"""

def feast(eu,cond,old,meal,other,val):
  new=[]
  while cond():
    new.append(meal())
    if eu==2: print(strist(1)(weave(*(new+old(),other)[::(-1)**val])),end='\r');sleep(1/2**5)
  return new

weave=lambda x,y: starmap(lambda i,j: i|j<<1,zip_longest(x,y,fillvalue=0))

def kolakoski(eu=0): #you see i ran out of letters and had to use the vowels in debug
  yield 1
  x=[];y=[1]
  while 1:
    if eu: print(strist(1)(weave(y,x)),2-watch(x));sleep(1/2**4)
    yield 2-watch(x)
    z=copy(y)
    if eu:
      z=feast(eu,lambda: not bite(z),lambda: x,lambda: not bite(x),y,1)+x
      x=[bite(z)]+z
      yy=feast(eu,munch:=lambda: bite(y)|bite(z),lambda: y,lambda: 0,x,0)+[1]
      while y: yy.append(munch())
      y=yy
    else: #i think this way is much more elegant and neatly tessellated together
      #but unfortunately humans appear to have eyes instead of brains that can execute and appreciate Python rapidly in their mind
      #sigh my art form shall forever remain beyond your species
      x,y=[bite(z:=X(lambda f: x if bite(z) else [not bite(x)]+f()))]+z),X(lambda f: [0]+f() if (munch:=lambda: bite(y)|bite(z))() else [1]+X(lambda g: y and [munch()]+g())


K = kolakoski(2) #2 to watch it traverse turingfully in real time, 1 to just see the states, 0 if it's okay because you can already taste RAM
print([next(K) for _ in range(100)])

'''btw (highly spoilerful; i recommend you dedicate yourself wholly to deciphering my pythology first)
this is just doing https://11011110.github.io/blog/2016/10/14/kolakoski-sequence-via.html if you are wondering'''