This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A370932 #21 Aug 07 2024 14:20:50 %S A370932 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, %T A370932 20,50,48,49,52,53,51,45,46,47,27,28,29,32,30,31,34,35,33,43,44,42,36, %U A370932 37,38,41,39,40,70,71,69,63,64,65,68,66,67,77,75,76,79,80 %N 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. %C A370932 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. %C A370932 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). %H A370932 Alois P. Heinz, <a href="/A370932/b370932.txt">Table of n, a(n) for n = 0..19682</a> %H A370932 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a> %F A370932 A081604(a(n)) = A081604(n). %F A370932 A122586(a(n)) = A122586(n). %e A370932 For n = 42: the ternary expansion of 42 is "1120"; also: %e A370932 + 1 = 1 (mod 3) %e A370932 - 1 + 1 = 0 (mod 3) %e A370932 + 1 - 1 + 2 = 2 (mod 3) %e A370932 - 1 + 1 - 2 + 0 = 1 (mod 3) %e A370932 - so the ternary expansion of a(42) is "1021", and a(42) = 34. %o A370932 (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); } %o A370932 (Python) %o A370932 from itertools import accumulate %o A370932 from sympy.ntheory import digits %o A370932 def A370932(n): %o A370932 t = accumulate(((-j if i&1 else j) for i, j in enumerate(digits(n,3)[1:])),func=lambda x,y: (x+y)%3) %o A370932 return int(''.join(str(-d%3 if i&1 else d) for i,d in enumerate(t)),3) # _Chai Wah Wu_, Mar 08 2024 %Y A370932 Cf. A006068 (base-2 analog), A081604, A105529, A122586, A071770 (inverse). %K A370932 nonn,look,base %O A370932 0,3 %A A370932 _Rémy Sigrist_, Mar 06 2024