s = [0] nb = 0 shuffle(vv,kk,v) = { my (done=1); for (i=1, #vv, if (kk[i] < #vv[i], kk[i]++; shuffle(vv,kk,v*2+vv[i][kk[i]]); kk[i]--; done = 0; ); ); if (done, if (nb++ > #s, s=concat(s, vector(#s)); ); s[nb] = v; ); } row(n) = { my (b = if (n, binary(n), [0])); nb = 0; shuffle([b,b],[0,0],0); Set(s[1..nb]); } { m = -1; for (n=0, 64, apply (v -> print (m++ " " v), row(n)); ); } quit