wanted = 10 000 s = [1, 2] \\ seed d = [] checked = 0 t = 0 n = 0 emit(v) = { print (n++ " " v); if (t < wanted, t += sumdigits(v); d = concat(d, digits(v)); if (!checked && #d >= #s, if (d[1..#s] == s, checked = 1, print ("# bug"); quit; ); ); ); } { for (v = 1, oo, t = if (v <= #s, s, d)[v]; for (i = 1, t, emit(v); ); if (n >= wanted, break; ); ); } quit