contains(x,y) = { my (m=10^#digits(y)); while (x>=y, if (x%m==y, return (1), x\=10; ); ); return (0); } odd part(n) = n/2^valuation(n,2) slot = [1] \\ next value by odd part unseen = 1 \\ unseen value seen(v) = { my (o=odd part(v)); while (#slot < o, slot = concat(slot, #slot+1); ); slot[o] > v; } other chain() = { my (c=unseen); for (x=1, oo, if (contains(c*=2, unseen), my (chain = unseen * powers(2, x)); slot[odd part(unseen)] *= 2^(x+1); while (seen(unseen), unseen++; ); return (chain); ); ); } a = vector(10 000) u = 1 { n = 0; for (c=1, oo, chain = other chain(); for (k=1, #chain, n++; if (chain[k]<=#a, a[chain[k]] = n; ); ); while (a[u], print (u " " a[u]); if (u++>#a, break (2); ); ); ); } quit