toruns(n) = { my (r=[]); while (n, my (v=valuation(n+n%2, 2)); n\=2^v; r=concat(v, r)); r } fromruns(r) = { my (v=0); for (k=1, #r, v=(v+k%2)*2^r[k]-k%2); v } a(n) = { my (r=toruns(n), o=1); while (o <= #r, if (r[o] > 1, r = concat([ r[1..o-1], [1, r[o]-1], r[o+1..#r] ]); ); o += 2; ); fromruns(r); } for (n=0, 2^13-1, print (n " " a(n))) quit