s = 0
unseen = 0
seen(v) = bittest(s, v)
see(v) = s = bitor(s, 2^v); while (seen(unseen), unseen++)

other(p) = {
	see(p);
	for (v=unseen, oo,
		if (!seen(v) && issquare(bitand(p, v)),
			return (v);
		);
	);
}

for (n=0, 2^13, print (n " " v=if (n==0, 0, other(v))))

quit