%I #17 Jun 23 2020 13:08:50
%S 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,
%T 10,9,11,14,15,18,22,24,25,27,27,27,28,27,28,30,30,29,29,27,26,26,24,
%U 24,25,24,22,21,18,18,19,18,19,21,21,20,20,18,16,15
%N 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].
%C This sequence has connections with a Takagi (or blancmange) curve.
%C Let t be the real function defined over [0..1] as follows:
%C - t(x) = 0 for x in [0..1/3],
%C - t(x) = x - 1/3 for x in ]1/3..2/3],
%C - t(x) = 1 - x for x in ]2/3..1].
%C Let g be the real function defined over [0..1] as follows:
%C - g(x) = Sum_{k >= 0} t(x * 3^k)/3^k.
%C 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.
%H Rémy Sigrist, <a href="/A309119/b309119.txt">Table of n, a(n) for n = 0..6560</a>
%H Rémy Sigrist, <a href="/A309119/a309119.png">Colored pinplot of the sequence for n = 0..3^7-1</a> (where the color denotes the contribution of the digits according to their position in the ternary expansion)
%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Blancmange_curve">Blancmange curve</a>
%F a(n) = Sum_{k = 0..n} (A062756(k) - A081603(k)).
%F a(n) >= 0 with equality iff n = 3^k - 1 for some k >= 0 (A024023).
%F a(3*k + 2) = 3*a(k) for any k >= 0.
%F a(3^k + m) = a(m) + m + 1 for any k >= 0 and m = 0..3^k-1.
%F a(2*3^k + m) = a(m) + 3^k - m - 1 for any k >= 0 and m = 0..3^k-1.
%e The first terms, alongside the ternary expansion of n and the corresponding number of 1's and 2's, are:
%e n a(n) ter(n) A062756(n) A081603(n)
%e -- ---- ------ ---------- ----------
%e 0 0 0 0 0
%e 1 1 1 1 0
%e 2 0 2 0 1
%e 3 1 10 1 0
%e 4 3 11 2 0
%e 5 3 12 1 1
%e 6 2 20 0 1
%e 7 2 21 1 1
%e 8 0 22 0 2
%e 9 1 100 1 0
%e 10 3 101 2 0
%t Accumulate[Table[Total[IntegerDigits[n,3]/.(2->-1)],{n,0,80}]] (* _Harvey P. Dale_, Jun 23 2020 *)
%o (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)) ", "))
%Y Cf. A024023, A062756, A081603.
%K nonn,look,base
%O 0,5
%A _Rémy Sigrist_, Jul 13 2019
|