A373712 a(n) is the least m >= 0 with the same number of ternary digits as n such that for some permutation p of 0..2, applying p to the ternary digits of n yields the ternary digits of m.
0, 1, 1, 3, 4, 3, 3, 3, 4, 9, 10, 11, 12, 13, 12, 11, 10, 9, 9, 11, 10, 11, 9, 10, 12, 12, 13, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 27, 29, 28, 33, 35, 34, 30, 32, 31, 35, 33, 34, 29, 27
Offset: 0
Examples
The first terms, alongside their ternary expansions, are: n a(n) ter(n) ter(a(n)) -- ---- ------ --------- 0 0 0 0 1 1 1 1 2 1 2 1 3 3 10 10 4 4 11 11 5 3 12 10 6 3 20 10 7 3 21 10 8 4 22 11 9 9 100 100 10 10 101 101 11 11 102 102 12 12 110 110 13 13 111 111 14 12 112 110 15 11 120 102 16 10 121 101
Links
- Rémy Sigrist, Table of n, a(n) for n = 0..6560
Programs
-
PARI
a(n, base = 3) = { my (d = digits(n, base), m = vector(base, i, -1), u = 1); for (i = 1, #d, if (m[1+d[i]] < 0, m[1+d[i]] = u; u = if (u==1, 0, u==0, 2, u+1);); d[i] = m[1+d[i]];); fromdigits(d, base); }
Formula
a(n) <= n.
a(a(n)) = a(n).
Comments