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), z=2); while (z <= #r, if (r[z] > 1, r = concat([ r[1..z-1], [1, r[z]-1], r[z+1..#r] ]); ); z += 2; ); fromruns(r); } for (n=0, 2^13-1, print (n " " a(n))) quit