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.

Showing 1-4 of 4 results.

A352760 Lexigraphically earliest sequence of distinct nonnegative integers such that for any n >= 0, among the ternary digits of n and a(n) (counted with multiplicity) there are as many 1's as 2's.

Original entry on oeis.org

0, 2, 1, 6, 8, 5, 3, 7, 4, 17, 20, 11, 24, 26, 18, 15, 23, 9, 14, 19, 10, 21, 25, 16, 12, 22, 13, 35, 53, 29, 56, 62, 47, 33, 51, 27, 60, 74, 54, 78, 80, 71, 59, 72, 44, 45, 61, 32, 65, 77, 50, 34, 52, 28, 38, 55, 30, 57, 69, 42, 36, 46, 31, 63, 73, 48, 75, 79
Offset: 0

Views

Author

Rémy Sigrist, Jul 05 2022

Keywords

Comments

This sequence is a self-inverse permutation of the nonnegative integers.

Examples

			The first terms, alongside their ternary expansions, are:
  n   a(n)  ter(n)  ter(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     2       1          2
   2     1       2          1
   3     6      10         20
   4     8      11         22
   5     5      12         12
   6     3      20         10
   7     7      21         21
   8     4      22         11
   9    17     100        122
  10    20     101        202
  11    11     102        102
  12    24     110        220
		

Crossrefs

Cf. A004488, A039001 (fixed points), A331275, A355504.

Programs

  • PARI
    See Links section.

Formula

a(n) = n iff n belongs to A039001.
a(n) < 3^k iff n < 3^k.

A340131 Numbers whose ternary expansions have the same number of 1's and 2's and, in each prefix (initial fragment), at least as many 1's as 2's.

Original entry on oeis.org

0, 5, 11, 15, 29, 33, 44, 45, 50, 83, 87, 98, 99, 104, 116, 128, 132, 135, 140, 146, 150, 245, 249, 260, 261, 266, 278, 290, 294, 297, 302, 308, 312, 332, 344, 348, 377, 380, 384, 395, 396, 401, 405, 410, 416, 420, 434, 438, 449, 450, 455, 731, 735, 746, 747
Offset: 1

Views

Author

Gennady Eremin, Dec 29 2020

Keywords

Comments

For a nonzero term, the ternary code starts with 1, otherwise the balance of 1's and 2's is broken already in the one-digit prefix. Therefore 7, 19, 21, etc. (see A039001) are not terms.
As another example, for the integer 52 the balance is broken in the three-digit prefix 122 (the entire ternary code is 1221).
Each term with a ternary code of length k corresponds one-to-one to the Motzkin path of length k that starts with an up step. Therefore, the terms can be called digitized Motzkin paths.
The number of terms with a ternary code of length k is equal to A244884(k). Example: five terms 29, 33, 44, 45 and 50 have a ternary length of 4, respectively A244884(4)=5.

Examples

			The first terms 0 and 5 are obvious, because the four intermediate ternary codes 1, 2, 10[3], and 11[4] are rejected due to a violation of the balance of 1's and 2's. Next, the successor function S works: for any term x, the next term is S(x).
Iterating over numbers is inefficient; code suffixes (final digits) can be processed faster. The transition from 0 to 12[5] is generalized for terms that are multiples of 9. For example,
S(10200[99]) = 10212[104], S(1122000[1188]) = 1122012[1193], etc.
In this case, the calculation of the subsequent term is reduced to simply replacing the suffix s = 00 with the subsequent suffix s'= 12.
Another common suffix is s = 02..2 = 02^k (twos are repeated at the end of the ternary code). Then the subsequent suffix is s'= 202..2 = 202^(k-1), i.e., within such a suffix, the first two digits are reversed. Here are some examples:
k = 1, S(1002[29]) = 1020[33], the increment is 4*3^0 = 4;
k = 2, S(110022[332]) = 110202[344], the increment is 4*3^1 = 12;
k = 3, S(10110222[2537]) = 10112022[2573], the increment is 4*3^2 = 36;
k = 4, S(111102222[9800]) = 111120222[9908], the increment is 4*3^3 = 108.
There are 5 such group suffixes.
		

Crossrefs

Subsequence of A039001.
Subsequences: A134752, A168607.
Cf. A244884.

Programs

  • PARI
    is(n) = {my(d = digits(n, 3), v = [0, 0]); for(i = 1, #d, if(d[i] > 0, v[d[i]]++); if(v[1] < v[2], return(0))); v[1] == v[2] } \\ David A. Corneth, Dec 29 2020
    
  • Python
    def digits(n, b):
      out = []
      while n >= b:
        out.append(n % b)
        n //= b
      return [n] + out[::-1]
    def ok(n):
      t = digits(n, 3)
      if t.count(1) != t.count(2): return False
      return all(t[:i].count(1) >= t[:i].count(2) for i in range(1, len(t)))
    print([n for n in range(750) if ok(n)]) # Michael S. Branicky, Dec 29 2020

A348516 a(n) is the least positive integer k such that the base 3 representation of n^k contains equally many 1's and 2's, or 0 if no k with this property exists.

Original entry on oeis.org

1, 0, 7, 0, 16, 1, 7, 1, 22, 0, 16, 1, 16, 6, 2, 1, 8, 6, 7, 1, 4, 1, 66, 9, 22, 3, 2, 0, 15, 1, 16, 2, 32, 1, 6, 9, 16, 2, 11, 6, 19, 13, 2, 13, 1, 1, 10, 22, 8, 2, 1, 6, 1, 159, 7, 1, 20, 1, 3, 6, 4, 2, 15, 1, 11, 3, 66, 6, 1, 9, 1, 6, 22, 2, 4, 3, 1, 2, 2, 2, 6
Offset: 0

Views

Author

Dimiter Skordev, Oct 21 2021

Keywords

Comments

a(3*n) = a(n) for any positive integer n because multiplication by 3 does not change the counts of the digits 1 and 2 in the base 3 representation. Hence a(n) reaches any of its values at infinitely many n.
There are infinitely many n with a(n) = 1 that are not divisible by 3, e.g. the numbers of the form (3^m + 2)(3^(m-1) + 3^(m-2) + ... + 3 + 1), m = 1, 2, 3, ...
Of course, a(n^a(n)) = 1 whenever a(n) > 0. More generally, if a(n) = p*q, where p and q are positive integers, then a(n^p) = q (hence any positive divisor of a nonzero term of the sequence is a term too). If a(n) = 0 then a(n^p) = 0 for any positive integer p.
In the absence of a proof that a(n) = 0 only for the numbers n which are powers of 3, it would be desirable to have at least an algorithm whose application to any concrete n answers the question whether a(n) = 0.
Except for the case when the number a(n) is 0, it is the least positive integer k such that n^k is a term of the sequence A039001.
Problem: Are there positive integers not occurring in the sequence a(1),a(2),a(3),...?

Examples

			a(2) = 7 because the base 3 representations of 2^1, 2^2, 2^3, 2^4, 2^5, 2^6 and 2^7 are 2, 11, 22, 121, 1012, 2101 and 11202 respectively.
		

Crossrefs

Cf. A039001.

Programs

  • Mathematica
    Array[If[IntegerQ@ Log[3, #], 0, Block[{k = 1}, While[Unequal @@ Most@ DigitCount[#^k, 3], k++]; k]] &, 72] (* Michael De Vlieger, Oct 21 2021 *)
  • PARI
    isp3(n) = my(q); isprimepower(n,&q) && (q==3);
    isok(k, n) = my(d=digits(n^k, 3)); #select(x->(x==1), d) == #select(x->(x==2), d);
    a(n) = if ((n==1) || isp3(n), return (0)); my(k=1); while (!isok(k, n), k++); k; \\ Michel Marcus, Oct 22 2021
  • Python
    h=[0,1,-1]
    def d(x):
        y,d=x,0
        while y>0: d,y=d+h[y%3],y//3
        return d
    def a(n):
        v,a,x=n,0,1
        while v%3==0: v=v//3
        if v>1:
            while d(x)!=0: a,x=a+1,v*x
        return a
    
  • Python
    from gmpy2 import digits
    def A348516(n):
        k, s = 1, digits(n,3).rstrip('0')
        if s == '1' or s == '': return 1-len(s)
        m = int(s,3)
        mk = m
        while s.count('1') != s.count('2'): k += 1; mk *= m; s = digits(mk,3)
        return k # Chai Wah Wu, Nov 11 2021
    

Extensions

a(0) from Michel Marcus, Nov 11 2021

A357616 Lexicographically earliest sequence of distinct nonnegative integers such that for any n >= 0, the number of 1's in the ternary expansion of n equals the number of 2's in the ternary expansion of a(n) and vice versa.

Original entry on oeis.org

0, 2, 1, 6, 8, 5, 3, 7, 4, 18, 20, 11, 24, 26, 17, 15, 23, 14, 9, 19, 10, 21, 25, 16, 12, 22, 13, 54, 56, 29, 60, 62, 35, 33, 47, 32, 72, 74, 51, 78, 80, 53, 59, 71, 44, 45, 61, 34, 65, 77, 50, 38, 52, 41, 27, 55, 28, 57, 69, 42, 30, 46, 31, 63, 73, 48, 75, 79
Offset: 0

Views

Author

Rémy Sigrist, Oct 06 2022

Keywords

Comments

This sequence is a self-inverse permutation of the nonnegative integers.

Examples

			The first terms, alongside their ternary expansions, are:
  n   a(n)  ter(n)  ter(a(n))
  --  ----  ------  ---------
   0     0       0          0
   1     2       1          2
   2     1       2          1
   3     6      10         20
   4     8      11         22
   5     5      12         12
   6     3      20         10
   7     7      21         21
   8     4      22         11
   9    18     100        200
  10    20     101        202
  11    11     102        102
  12    24     110        220
		

Crossrefs

Programs

  • PARI
    See Links section.

Formula

A081603(a(n)) = A062756(n).
A062756(a(n)) = A081603(n).
a(n) < 3^k iff n < 3^k.
a(n) = n iff n belongs to A039001.
Empirically:
- a(n) = n/2 iff n belongs to A005823,
- a(n) = 2*n iff n belongs to A005836.
Showing 1-4 of 4 results.