s = 0 unseen = 1 seen(v) = bit test(s, v) see(v) = s = bit or(s, 2^v); while (seen(unseen), unseen++) other(p) = { see(p); my (h=sumdigits(p, 2)); for (v=unseen, oo, if (!seen(v) && h <= sumdigits(v,3), return (v); ); ); } v=1; for (n=1, 100 000, print (n " " v " " unseen); v=other(v)); quit