OFFSET
0,4
LINKS
Alois P. Heinz, Antidiagonals d = 0..140, flattened
FORMULA
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.
EXAMPLE
Table begins:
0 1 2 3 4 5 6 ...
1 2 0 4 5 3 7 ...
2 0 1 5 3 4 8 ...
3 4 5 6 7 8 0 ...
4 5 3 7 8 6 1 ...
5 3 4 8 6 7 2 ...
6 7 8 0 1 2 3 ...
...
MAPLE
T:= proc(n, m) local t, h, r, i;
t, h, r:= n, m, 0;
for i from 0 while t>0 or h>0 do
r:= r +3^i *irem(irem(t, 3, 't') +irem(h, 3, 'h'), 3)
od; r
end:
seq(seq(T(n, d-n), n=0..d), d=0..12); # Alois P. Heinz, Sep 07 2011
MATHEMATICA
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 *)
PROG
(PARI) T(n, m) = fromdigits(Vec(Pol(digits(n, 3)) + Pol(digits(m, 3)))%3, 3); \\ Kevin Ryde, Apr 06 2021
(Python)
def T(n, m):
k, pow3 = 0, 1
while n + m > 0:
n, rn = divmod(n, 3)
m, rm = divmod(m, 3)
k, pow3 = k + pow3*((rn+rm)%3), pow3*3
return k
print([T(n, d-n) for d in range(14) for n in range(d+1)]) # Michael S. Branicky, May 04 2021
CROSSREFS
AUTHOR
EXTENSIONS
More terms from Larry Reeves (larryr(AT)acm.org), Jan 23 2001
STATUS
approved