Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
A370932
For any number n >= 0 with ternary expansion Sum_{i >= 0} t_i * 3^i, a(n) = Sum_{i >= 0} ((Sum_{j >= 0} (-1)^j * t_{i+j}) mod 3) * 3^i.
2
0, 1, 2, 5, 3, 4, 7, 8, 6, 16, 17, 15, 9, 10, 11, 14, 12, 13, 23, 21, 22, 25, 26, 24, 18, 19, 20, 50, 48, 49, 52, 53, 51, 45, 46, 47, 27, 28, 29, 32, 30, 31, 34, 35, 33, 43, 44, 42, 36, 37, 38, 41, 39, 40, 70, 71, 69, 63, 64, 65, 68, 66, 67, 77, 75, 76, 79, 80
OFFSET
0,3
COMMENTS
In other words, the k-th ternary digit of a(n) is congruent (modulo 3) to the alternate sum of the digits to the left of (and including) the k-th ternary digit of n.
This sequence is a permutation of the nonnegative integers with inverse A071770 that preserves the number of ternary digits (A081604) and the leading ternary digit (A122586).
FORMULA
A081604(a(n)) = A081604(n).
A122586(a(n)) = A122586(n).
EXAMPLE
For n = 42: the ternary expansion of 42 is "1120"; also:
+ 1 = 1 (mod 3)
- 1 + 1 = 0 (mod 3)
+ 1 - 1 + 2 = 2 (mod 3)
- 1 + 1 - 2 + 0 = 1 (mod 3)
- so the ternary expansion of a(42) is "1021", and a(42) = 34.
PROG
(PARI) a(n, base = 3) = { my (d = digits(n, base), s = 0); for (i = 1, #d, d[i] = (s = d[i]-s) % base; ); fromdigits(d, base); }
(Python)
from itertools import accumulate
from sympy.ntheory import digits
def A370932(n):
t = accumulate(((-j if i&1 else j) for i, j in enumerate(digits(n, 3)[1:])), func=lambda x, y: (x+y)%3)
return int(''.join(str(-d%3 if i&1 else d) for i, d in enumerate(t)), 3) # Chai Wah Wu, Mar 08 2024
CROSSREFS
Cf. A006068 (base-2 analog), A081604, A105529, A122586, A071770 (inverse).
Sequence in context: A026258 A357047 A105530 * A245815 A105108 A118460
KEYWORD
nonn,look,base
AUTHOR
Rémy Sigrist, Mar 06 2024
STATUS
approved