s = 0 unseen = 1 seen(v) = bit test(s, v) see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++) a = vector(10001, n, -1) u = 0 n=-1 emit(v) = { n++; if (v+1<=#a, a[v+1] = n; while (a[u+1]>=0, print (u " " a[u+1]); if (1+u++>#a, quit; ); ); ); see(v) } \\ n-th term without common bit with x avoid(x,n) = { my (v=0, b=1); while (n, if (x%2==0, if (n%2, v+=b; ); n\=2 ); x\=2; b*=2; ); v } { v=0; while (1, emit(v); if (bitand(v, unseen)==0, v=unseen, x = bitor(v,unseen); for (i=0, oo, c=avoid(x,i); if (!seen(c), emit(c); v=unseen; break; ); ); ); ); } quit