Maple 9 code for A151949 and A151959 from R. J. Mathar, Aug 19 2009: A151949 := proc(n) tdigs := convert(n,base,10) ; tup := sort(tdigs) ; add( (op(i,tup)-op(-i,tup)) *10^(i-1),i=1..nops(tup)) : end: N := 10 : allc := [seq(10000000000000000000000000000000,i=1..N)] : cyK := proc(n,) global allc,N ; L := [n] ; k := n ; while true do k := A151949(k) ; if k in L then for s from 1 do if op(-s,L) = k then cur := op(s,allc) ; if k < cur then printf("%a %d %d\n",L,s,k) ; allc := subsop(s=k,allc) ; fi; RETURN(s) ; fi; od: break; fi; L := [op(L),k] : od: end: for n from 1 do cyK(n) ; od: