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++) contains(x,y) = { my (m=10^#digits(y)); while (x>=y, if (x%m==y, return (1), x\=10; ); ); return (0); } other chain() = { my (w=unseen); for (x=1, oo, if (contains(w*=2, unseen), my (chain = unseen*powers(2, x)); apply(see, chain); return (chain); ); ); } { for (c=1, oo, my (chain = other chain()); apply(v -> print (n++ " " v), chain); if (n>=10 000, break); ); } quit