%I #9 Apr 07 2020 12:19:48
%S 0,1,-1,3,2,4,-3,-4,-2,9,8,10,6,7,5,12,13,11,-9,-10,-8,-12,-11,-13,-6,
%T -5,-7,27,26,28,24,25,23,30,31,29,18,19,17,21,20,22,15,14,16,36,37,35,
%U 39,38,40,33,32,34,-27,-28,-26,-30,-29,-31,-24,-23,-25,-36
%N Replace 2's with (-1)'s in ternary representation of n and sum nonzero terms with alternating signs.
%C This sequence is a variant of A117966, and shares features with A065620.
%C Every integer appears exactly once in this sequence.
%H Rémy Sigrist, <a href="/A333773/b333773.txt">Table of n, a(n) for n = 0..6561</a>
%F a(3*n) = 3*a(n).
%F a(3*n+1) = 3*a(n) + (-1)^A160384(n).
%F a(3*n+2) = 3*a(n) - (-1)^A160384(n).
%F Sum_{k=0..n} a(k) >= 0 with equality iff n belongs to A024023.
%F a(n) > 0 iff n belongs to A132141.
%F a(n) < 0 iff n belongs to A157671.
%F a(A004488(n)) = -a(n).
%e For n = 97:
%e - 97 = 3^4 + 3^2 + 2*3^1 + 3^0,
%e - hence a(97) = 3^4 - 3^2 + (-1)*3^1 - 3^0 = 68.
%o (PARI) a(n) = { my (v=0, t=Vecrev(digits(n,3))); for (k=1, #t, if (t[k]==1, v=+3^(k-1)-v, t[k]==2, v=-3^(k-1)-v)); v }
%Y Cf. A004488, A024023, A065620, A117966, A132141, A157671, A160384, A333780.
%K sign,base
%O 0,4
%A _Rémy Sigrist_, Apr 05 2020