Task

Create a Thue-Morse sequence.



See also
   YouTube entry: The Fairest Sharing Sequence Ever
   YouTube entry: Math and OCD - My story with the Thue-Morse sequence
   Task: Fairshare between two and more


import sequtils, strutils
 
iterator thueMorse(maxSteps = int.high): string =
  var val = @[0]
  var count = 0
  while true:
    yield val.join()
    inc count
    if count == maxSteps: break
    val &= val.mapIt(1 - it)
 
for bits in thueMorse(6):
  echo bits