%I #33 Jul 09 2018 12:15:01
%S 1,3,9,27,72,216,612,1836,6381,19143,34191,102573,375201,1125603,
%T 3065211,9195633,27586899,99868572,299605716,617506992,1852520976,
%U 6790252581,20370757743,34775707302,104327121906,609121723401,1827365170203,3020715637281,9062146911843
%N Reverse or triple: if reverse(a(n)) > a(n), a(n+1) = reverse(a(n)), else a(n+1) = 3*a(n).
%H Robert Israel, <a href="/A042938/b042938.txt">Table of n, a(n) for n = 1..1951</a>
%e Starting with 1, the reverse is 1 and not greater than 1 so the next term is 3. The reverse of 3 is also not greater than 3 and so the next term is 9. The reverse of 9 is not greater than 9 and so the next term is 27. However, the reverse of 27 is 72 which is greater and so the next term in the sequence is 72 and so on.
%p reverse:= proc(n)
%p local L,i,m;
%p L:= convert(n,base,10);
%p m:= nops(L);
%p add(L[i]*10^(m-i),i=1..m);
%p end proc:
%p a[1]:= 1:
%p for n from 2 to 100 do
%p r:= reverse(a[n-1]);
%p if r > a[n-1] then a[n]:= r
%p else a[n]:= 3*a[n-1]
%p fi
%p od:
%p seq(a[i],i=1..100); # _Robert Israel_, Jun 24 2015
%t rd[n_]:=Module[{rev=FromDigits[Reverse[IntegerDigits[n]]]}, If[rev>n, rev, 3 n]]; NestList[rd, 1, 30] (* _Vincenzo Librandi_, Jun 24 2015 *)
%t NestList[If[IntegerReverse[#]>#,IntegerReverse[#],3#]&,1,30] (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Jul 09 2018 *)
%o (PARI) lista(nn) = {print1(a=1, ", "); for (n=2, nn, r = eval(concat(Vecrev(Str(a)))); if (r > a, a = r, a *= 3); print1(a, ", "););} \\ _Michel Marcus_, Jan 31 2016
%K base,nonn
%O 1,2
%A _Dann Toliver_
%E Corrected by _Robert Israel_, Jun 24 2015