cp's OEIS Frontend

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.

A309119 a(n) is the number of 1's minus the number of 2's among the ternary representations of the integers in the interval [0..n].

Original entry on oeis.org

0, 1, 0, 1, 3, 3, 2, 2, 0, 1, 3, 3, 5, 8, 9, 9, 10, 9, 8, 8, 6, 6, 7, 6, 4, 3, 0, 1, 3, 3, 5, 8, 9, 9, 10, 9, 11, 14, 15, 18, 22, 24, 25, 27, 27, 27, 28, 27, 28, 30, 30, 29, 29, 27, 26, 26, 24, 24, 25, 24, 22, 21, 18, 18, 19, 18, 19, 21, 21, 20, 20, 18, 16, 15
Offset: 0

Views

Author

Rémy Sigrist, Jul 13 2019

Keywords

Comments

This sequence has connections with a Takagi (or blancmange) curve.
Let t be the real function defined over [0..1] as follows:
- t(x) = 0 for x in [0..1/3],
- t(x) = x - 1/3 for x in ]1/3..2/3],
- t(x) = 1 - x for x in ]2/3..1].
Let g be the real function defined over [0..1] as follows:
- g(x) = Sum_{k >= 0} t(x * 3^k)/3^k.
The representation of n -> (n/3^k, a(n)/3^k) for n = 0..3^k converges to the representation of g over [0..1] as k tends to infinity.

Examples

			The first terms, alongside the ternary expansion of n and the corresponding number of 1's and 2's, are:
  n   a(n)  ter(n)  A062756(n)  A081603(n)
  --  ----  ------  ----------  ----------
   0     0       0           0           0
   1     1       1           1           0
   2     0       2           0           1
   3     1      10           1           0
   4     3      11           2           0
   5     3      12           1           1
   6     2      20           0           1
   7     2      21           1           1
   8     0      22           0           2
   9     1     100           1           0
  10     3     101           2           0
		

Crossrefs

Programs

  • Mathematica
    Accumulate[Table[Total[IntegerDigits[n,3]/.(2->-1)],{n,0,80}]] (* Harvey P. Dale, Jun 23 2020 *)
  • PARI
    s = 0; for (n=0, 73, t = digits(n,3); print1 (s+=sum(i=1, #t, if (t[i]==1, +1, t[i]==2, -1, 0)) ", "))

Formula

a(n) = Sum_{k = 0..n} (A062756(k) - A081603(k)).
a(n) >= 0 with equality iff n = 3^k - 1 for some k >= 0 (A024023).
a(3*k + 2) = 3*a(k) for any k >= 0.
a(3^k + m) = a(m) + m + 1 for any k >= 0 and m = 0..3^k-1.
a(2*3^k + m) = a(m) + 3^k - m - 1 for any k >= 0 and m = 0..3^k-1.