%I #32 Dec 26 2021 20:57:35
%S 0,1,1,2,2,2,3,0,0,3,4,4,1,4,4,5,5,5,5,5,5,6,3,3,6,3,3,6,7,7,4,7,7,4,
%T 7,7,8,8,8,8,8,8,8,8,8,9,6,6,0,6,6,0,6,6,9,10,10,7,1,1,7,1,1,7,10,10,
%U 11,11,11,2,2,2,2,2,2,11,11,11,12,9,9,12,0,0,3,0,0,12,9,9,12,13,13,10,13,13,1,4,4,1,13,13,10,13,13
%N Table of tersums m + n (answers written in base 10).
%H Alois P. Heinz, <a href="/A004489/b004489.txt">Antidiagonals d = 0..140, flattened</a>
%F Tersum m + n: write m and n in base 3 and add mod 3 with no carries, e.g. 5 + 8 = "21" + "22" = "10" = 1.
%e Table begins:
%e 0 1 2 3 4 5 6 ...
%e 1 2 0 4 5 3 7 ...
%e 2 0 1 5 3 4 8 ...
%e 3 4 5 6 7 8 0 ...
%e 4 5 3 7 8 6 1 ...
%e 5 3 4 8 6 7 2 ...
%e 6 7 8 0 1 2 3 ...
%e ...
%p T:= proc(n, m) local t, h, r, i;
%p t, h, r:= n, m, 0;
%p for i from 0 while t>0 or h>0 do
%p r:= r +3^i *irem(irem(t, 3, 't') +irem(h, 3, 'h'), 3)
%p od; r
%p end:
%p seq(seq(T(n, d-n), n=0..d), d=0..12); # _Alois P. Heinz_, Sep 07 2011
%t T[n_, m_] := Module[{t, h, r, i, remt, remh}, {t, h, r} = {n, m, 0}; For[i = 0, t>0 || h>0, i++, r = r + 3^i*Mod[({t, remt} = QuotientRemainder[t, 3 ]; remt) + ({h, remh} = QuotientRemainder[h, 3]; remh), 3]]; r]; Table[Table[T[n, d-n], {n, 0, d}], {d, 0, 13}] // Flatten (* _Jean-François Alcover_, Jan 07 2014, translated from Maple *)
%o (PARI) T(n,m) = fromdigits(Vec(Pol(digits(n,3)) + Pol(digits(m,3)))%3, 3); \\ _Kevin Ryde_, Apr 06 2021
%o (Python)
%o def T(n, m):
%o k, pow3 = 0, 1
%o while n + m > 0:
%o n, rn = divmod(n, 3)
%o m, rm = divmod(m, 3)
%o k, pow3 = k + pow3*((rn+rm)%3), pow3*3
%o return k
%o print([T(n, d-n) for d in range(14) for n in range(d+1)]) # _Michael S. Branicky_, May 04 2021
%Y Similar to but different from A004481.
%Y Main diagonal gives A004488.
%Y Cf. A003987 (analogous sequence for base 2).
%K nonn,base,tabl,look,easy,nice
%O 0,4
%A _N. J. A. Sloane_
%E More terms from Larry Reeves (larryr(AT)acm.org), Jan 23 2001