A371275 a(n) is the number of runs in the balanced ternary expansion of n.
0, 1, 2, 2, 1, 2, 3, 3, 3, 2, 3, 2, 2, 1, 2, 3, 3, 4, 3, 4, 4, 4, 3, 3, 4, 4, 3, 2, 3, 4, 4, 3, 2, 3, 3, 3, 2, 3, 2, 2, 1, 2, 3, 3, 4, 3, 4, 4, 4, 3, 4, 5, 5, 4, 3, 4, 5, 5, 4, 4, 5, 5, 5, 4, 5, 4, 4, 3, 3, 4, 4, 5, 4, 5, 5, 5, 4, 3, 4, 4, 3, 2, 3, 4, 4, 3, 4
Offset: 0
Examples
The first terms, alongside the balanced ternary expansion of n, are: n a(n) bter(n) --- ---- ------- 0 0 0 1 1 1 2 2 1T 3 2 10 4 1 11 5 2 1TT 6 3 1T0 7 3 1T1 8 3 10T 9 2 100 10 3 101 11 2 11T 12 2 110 13 1 111 14 2 1TTT 15 3 1TT0
Programs
-
PARI
a(n) = { my (r = 0, d); while (n, r++; d = centerlift(Mod(n, 3)); while (d==centerlift(Mod(n, 3)), n = (n-d)/3;);); return (r); }
Comments