Post History
Python 3.8, 64 bytes lambda s,_:((n:=s.count("1"))*"1"+"0"+n*"1010")*(len(s)-n)+n*"1" Try it online! Let Tn consist of (2n+1) 0s and 2n 1s alternating. Tn can consume a 1 on either side and ...
#1: Initial revision
# [Python 3.8], 64 bytes
<!-- language-all: lang-python -->
lambda s,_:((n:=s.count("1"))*"1"+"0"+n*"1010")*(len(s)-n)+n*"1"
[Try it online!][TIO-m9dy2job]
[Python 3.8]: https://docs.python.org/3.8/
[TIO-m9dy2job]: https://tio.run/##bZLBTsMwDIbPzVNYOSVrViUgJFTRC@LMC4wJZTQVRcWtkkzqNO3Zi9NuMBCX9P/t@KtddzjE9x5v7wc/NdXL1NnPXW0hqNdSCCyrULz1e4yCGy7lis6ca54jKW00lyvRORRBrlHOQT5ZqKDFYR@FZLsrbUNwPkJwUVgJDxUcCaSo4gQWawi9j65Oqaq6mJ1kjXeBII2wCsgOvqVeUlAyVrsG0IUoRgUHBShLlnkX9x5hhBUg5HBIT9b0HgI1AptE2aZrxNxsWeas71rnDVnNss7GRV8PzbJU/pbKA1VmbUOGeqRcsj@IvAKTAmfK@mx9YYfBYS04GEi4zHXBlb9S8xR8Q3kFHDTQzfnckl9wUv5h6YX1D@O7fobNjEuPiZJG57z46FsUnvzySZM6b8gX0VsM6b3iqMcbXcJzj06BHu8er/TTok/zxtJKJmO01oz@C22@AA "Python 3.8 (pre-release) – Try It Online"
Let T<sub><i>n</i></sub> consist of (2<i>n</i>+1) `0`s and 2<i>n</i> `1`s alternating. T<sub><i>n</i></sub> can consume a 1 on either side and become T<sub><i>n</i>-1</sub>:
```` lang-none
[1 0101]01010
01010[1010 1]
````
Repeating this, T<sub><i>n</i></sub> can consume <i>n</i> 1s in total from both sides and become T<sub>0</sub> = `0`.
The output alternates <i>m</i>+1 runs of <i>n</i> 1s with <i>m</i> copies of T<sub><i>n</i></sub>.
This can be reduced to any string of <i>m</i> 0s and <i>n</i> 1s.
