A319651 Largest number having in its ternary representation the same number of 0's, 1's and 2's as n.
0, 1, 2, 3, 4, 7, 6, 7, 8, 9, 12, 21, 12, 13, 22, 21, 22, 25, 18, 21, 24, 21, 22, 25, 24, 25, 26, 27, 36, 63, 36, 39, 66, 63, 66, 75, 36, 39, 66, 39, 40, 67, 66, 67, 76, 63, 66, 75, 66, 67, 76, 75, 76, 79, 54, 63, 72, 63, 66, 75, 72, 75, 78, 63, 66, 75, 66, 67, 76, 75, 76
Offset: 0
Links
- Seiichi Manyama, Table of n, a(n) for n = 0..6560
Crossrefs
Programs
-
Mathematica
Table[FromDigits[ReverseSort[IntegerDigits[n, 3]], 3], {n, 0, 100}] (* Paolo Xausa, Aug 07 2024 *)
-
PARI
a(n) = fromdigits(vecsort(digits(n, 3),,4), 3); \\ Michel Marcus, Sep 25 2018
-
Python
from gmpy2 import digits def A319651(n): return int(''.join(sorted(digits(n,3),reverse=True)),3) # Chai Wah Wu, Sep 26 2018
-
Ruby
def A(k, n) (0..n).map{|i| i.to_s(k).split('').sort.reverse.join.to_i(k)} end p A(3, 100)
Formula
n <= a(n) < 3n. - Charles R Greathouse IV, Aug 07 2024