a(n, {base=3}) = \ my (dig=[]); \ my (len=[]); \ while (n, \ my (d=n%base); \ my (l=0); \ while (n%base==d, \ l++; \ n \= base; \ ); \ dig = concat([d], dig); \ len = concat([l], len); \ ); \ len = Vecrev(len); \ my (v=0); \ for (i=1, #len, \ v = v*base^len[i] + (base^len[i]-1)/(base -1)*dig[i] \ ); \ return (v) for (n=0, 3^8-1, print (n " " a(n))) quit