base = 10 first(n) = ((n%(base-1))+1)*base^(n\(base-1))-1 nxt(n) = { my (r=0, p=0, d); while (1, d = n%base; if (d<(base-1) && r>0, return ((n+1)*base^p + first(r-1)) ); n = n\base; p = p+1; r = r+d ) } { print ("0 0"); a = vector(10 000); u = 1; n = 0; for (w=1, 5, for (s=1, w*(base-1), v=base^(w-1)+first(s-1); while (v<base^w, n++; if (v<=#a, a[v] = n; while (a[u], print (u " " a[u]); if (u++ > #a, break (4); ); ); ); v=nxt(v); ); ); ); } quit