%I #18 Dec 26 2019 05:44:55
%S 0,1,2,1,4,5,2,7,8,1,10,11,4,11,14,5,4,17,2,11,20,7,22,7,8,25,22,1,28,
%T 7,10,11,4,11,14,5,4,17,2,11,40,41,14,41,44,5,14,47,4,41,50,17,52,17,
%U 2,55,52,11,58,17,20,7,22,7,8,25,22,1,28,7,70,71,8
%N Starting from n: as long as the decimal representation contains a positive multiple of 3, divide the largest and leftmost such substring by 3; a(n) corresponds to the final value.
%C This sequence is a variant of A329424.
%H Robert Israel, <a href="/A330355/b330355.txt">Table of n, a(n) for n = 0..10000</a>
%H Rémy Sigrist, <a href="/A330355/a330355_1.gp.txt">PARI program for A330355</a>
%F a(n) <= n with equality iff n = 0 or n belongs to A325112.
%F a(3^k) = 1 for any k >= 0.
%e For n = 193:
%e - 193 gives 1 followed by 93/3 = 131,
%e - 131 gives 1 followed by 3/3 followed by 1 = 111,
%e - 111 gives 111/3 = 37,
%e - 37 gives 3/3 followed by 7 = 17,
%e - neither 1, 7 nor 17 are divisible by 3, so a(193) = 17.
%p f:= proc(n) option remember; local L,m,i,d,np1,j,s;
%p L:= convert(n,base,10);
%p m:= nops(L);
%p for d from m to 1 by -1 do
%p for i from 1 to m-d+1 do
%p s:= convert(L[i..i+d-1],`+`);
%p if s > 0 and s mod 3 = 0 then
%p np1:= add(L[j]*10^(j-1),j=1..i-1)+1/3*add(L[j]*10^(j-1),j=i..i+d-1);
%p return procname(np1 + 10^(2+ilog10(np1)-(i+d))*add(L[j]*10^(j-1),j=i+d..m));
%p fi
%p od
%p od;
%p n
%p end proc:
%p map(f, [$0..100]); # _Robert Israel_, Dec 25 2019
%o (PARI) See Links section.
%Y Cf. A325112, A327539, A329424.
%K nonn,base,look
%O 0,3
%A _Rémy Sigrist_, Dec 11 2019