from itertools import groupby
s = "01"
l = []
q = [(s, [])]
m = 5
f = lambda s: [len(list(g)) for k, g in groupby(s)]
while q:
x, ops = q.pop()
l.append((x, f(x), ops))
n = len(x)
for a in range(n + 1):
for b in range(a + 1, n + 1):
u = x[:a] + x[a:b] * 2 + x[b:]
if len(u) <= m:
q.append((u, ops + [(a, b)]))
for e in l:
print(e)
To embed this project on your website, copy the following code and paste it into your website's HTML: