big = 1 000 000 s = 0 S = Set([]) unseen = 1 seen(v) = if (v < big, bit test(s, v), set search(S, v)) see(v) = if (v < big, s = bit or(s, 2^v), S = set union(S, Set([v]))); while (seen(unseen), unseen++) other(p) = { see(p); my (w=#binary(p), v); \\ invert leftmost binary digit ? forstep (b=w-1, 0, -1, v = bitxor(p, 2^b); if (!seen(v), return (v); ); ); \\ invert rightmost leading zero ? for (b=w, oo, v = bitxor(p, 2^b); if (!seen(v), return (v); ); ); } v=0; for (n=0, 2^13-1, print (n " " v); v=other(v)) quit