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++) n = 0 emit(v) = { my (p=vecprod(if (v, digits(v), [0]))); if (!seen(p), print (n++ " " v); if (n==10 000, quit, see(p)); ); } explore(v, r, d) = { if (r==0, emit(v), while (d<10, explore(v*10+d, r-1, d); d++; ); ); } emit(0) emit(1) for (w=1, oo, explore(0, w, 2)) quit