s = 0
unseen = 1
seen(v) = bit test(s, v)
see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++)

cc = [0]

other(p) = {
	see(p);
	my (w=1, b, c);
	for (e=0, oo,
		if (!bittest(p, e),
			if (#cc==w,
				cc=concat(cc, vector(#cc));
			);
			b = 2^e;
			for (k=1, w,
				c = cc[w+k] = b+cc[k];
				if (!seen(c),
					return (c);
				);
			);

			w*=2;
		);
	);
}

{
	v = 0;
	for (n=1, 10 000,
		v = other(v);
		print (n " " #binary(v));
	);
}

quit