s = 0 unseen = 0 seen(v) = bittest(s, v) see(v) = s = bitor(s, 2^v); while (seen(unseen), unseen++) toruns(n) = { my (r=[]); while (n, my (v=valuation(n+n%2, 2)); n\=2^v; r=concat(v, r)); r } fromruns(r) = { my (v=0); for (k=1, #r, v=(v+k%2)*2^r[k]-k%2); v } vv = [0] row(n) = { my (r=vecsort(toruns(n)), nb=0); forperm (r, p, if (nb++ > #vv, vv = concat(vv, vector(#vv)); ); vv[nb] = fromruns(Vec(p)); ); Set(vv[1..nb]); } { a = vector(2^13-1); u = 1; m = 0; print ("0 0"); for (n=1, #a, if (!seen(n), r=row(n); for (k=1, #r, see(r[k]); a[r[k]] = m++; ); while (u <= #a && a[u], print (u " " a[u]); u++; ); ); ); } quit