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.

A117966 Balanced ternary enumeration (based on balanced ternary representation) of integers; write n in ternary and then replace 2's with (-1)'s.

Original entry on oeis.org

0, 1, -1, 3, 4, 2, -3, -2, -4, 9, 10, 8, 12, 13, 11, 6, 7, 5, -9, -8, -10, -6, -5, -7, -12, -11, -13, 27, 28, 26, 30, 31, 29, 24, 25, 23, 36, 37, 35, 39, 40, 38, 33, 34, 32, 18, 19, 17, 21, 22, 20, 15, 16, 14, -27, -26, -28, -24, -23, -25, -30, -29, -31, -18, -17, -19, -15, -14, -16, -21, -20, -22, -36
Offset: 0

Views

Author

Keywords

Comments

As the graph demonstrates, there are large discontinuities in the sequence between terms 3^i-1 and 3^i, and between terms 2*3^i-1 and 2*3^i. - N. J. A. Sloane, Jul 03 2016

Examples

			7 in base 3 is 21; changing the 2 to a (-1) gives (-1)*3+1 = -2, so a(7) = -2. I.e., the number of -2 according to the balanced ternary enumeration is 7, which can be obtained by replacing every -1 by 2 in the balanced ternary representation (or expansion) of -2, which is -1,1.
		

References

  • D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, Vol. 2, pp. 173-175; 2nd. ed. pp. 190-193.

Crossrefs

Programs

  • Maple
    f:= proc(n) local L,i;
       L:= subs(2=-1,convert(n,base,3));
       add(L[i]*3^(i-1),i=1..nops(L))
    end proc:
    map(f, [$0..100]);
    # alternate:
    N:= 100: # to get a(0) to a(N)
    g:= 0:
    for n from 1 to ceil(log[3](N+1)) do
    g:= convert(series(3*subs(x=x^3,g)*(1+x+x^2)+x/(1+x+x^2),x,3^n+1),polynom);
    od:
    seq(coeff(g,x,j),j=0..N); # Robert Israel, Nov 17 2015
    # third Maple program:
    a:= proc(n) option remember; `if`(n=0, 0,
          3*a(iquo(n, 3, 'r'))+`if`(r=2, -1, r))
        end:
    seq(a(n), n=0..3^4-1);  # Alois P. Heinz, Aug 14 2019
  • Mathematica
    Map[FromDigits[#, 3] &, IntegerDigits[#, 3] /. 2 -> -1 & /@ Range@ 80] (* Michael De Vlieger, Nov 17 2015 *)
  • PARI
    a(n) = subst(Pol(apply(x->if(x == 2, -1, x), digits(n,3)), 'x), 'x, 3)
    vector(73, i, a(i-1))  \\ Gheorghe Coserea, Nov 17 2015
    
  • Python
    def a(n):
        if n==0: return 0
        if n%3==0: return 3*a(n//3)
        elif n%3==1: return 3*a((n - 1)//3) + 1
        else: return 3*a((n - 2)//3) - 1
    print([a(n) for n in range(101)]) # Indranil Ghosh, Jun 06 2017

Formula

a(0) = 0, a(3n) = 3a(n), a(3n+1) = 3a(n)+1, a(3n+2) = 3a(n)-1.
G.f. satisfies A(x) = 3*A(x^3)*(1+x+x^2) + x/(1+x+x^2). - corrected by Robert Israel, Nov 17 2015
A004488(n) = a(n)^{-1}(-a(n)). I.e., if a(n) <= 0, A004488(n) = A117967(-a(n)) and if a(n) > 0, A004488(n) = A117968(a(n)).
a(n) = n - 3 * A005836(A289814(n) + 1). - Andrey Zabolotskiy, Nov 11 2019

Extensions

Name corrected by Andrey Zabolotskiy, Nov 10 2019

A309991 Balanced quinary (base 5) enumeration (or balanced quinary representation) of integers, write n in quinary, and then replace 3's with (-2)'s and 4's with (-1)'s.

Original entry on oeis.org

0, 1, 2, -2, -1, 5, 6, 7, 3, 4, 10, 11, 12, 8, 9, -10, -9, -8, -12, -11, -5, -4, -3, -7, -6, 25, 26, 27, 23, 24, 30, 31, 32, 28, 29, 35, 36, 37, 33, 34, 15, 16, 17, 13, 14, 20, 21, 22, 18, 19, 50, 51, 52, 48, 49, 55, 56, 57, 53, 54, 60, 61, 62, 58, 59, 40, 41
Offset: 0

Views

Author

Jackson Haselhorst, Aug 26 2019

Keywords

Comments

This sequence, like the balanced ternary sequence, will eventually include every integer exactly once.

Crossrefs

Cf. A117966.
Column k=2 of A319047.

Programs

  • Maple
    a:= proc(n) option remember; `if`(n=0, 0,
          5*a(iquo(n, 5))+mods(n, 5))
        end:
    seq(a(n), n=0..100);  # Alois P. Heinz, Aug 26 2019
  • Mathematica
    Table[FromDigits[IntegerDigits[n,5]/.{3->-2,4->-1},5],{n,0,120}] (* Harvey P. Dale, Sep 05 2020 *)
  • PARI
    a(n) = subst(Pol(apply(d->if(d>2, d-5, d), digits(n, 5)), 'x), 'x, 5) \\ Andrew Howroyd, Aug 26 2019

A309995 Balanced septenary enumeration (or balanced septenary representation) of integers; write n in septenary and then replace 4's with (-3),s, 5's with (-2)'s, and 6's with (-1)'s.

Original entry on oeis.org

0, 1, 2, 3, -3, -2, -1, 7, 8, 9, 10, 4, 5, 6, 14, 15, 16, 17, 11, 12, 13, 21, 22, 23, 24, 18, 19, 20, -21, -20, -19, -18, -24, -23, -22, -14, -13, -12, -11, -17, -16, -15, -7, -6, -5, -4, -10, -9, -8, 49, 50, 51, 52, 46, 47, 48, 56, 57, 58, 59, 53, 54, 55, 63
Offset: 0

Views

Author

Jackson Haselhorst, Aug 26 2019

Keywords

Comments

This sequence, like the balanced ternary and quinary sequences, includes every integer exactly once.

Examples

			As 54_10 = 105_7, the digits of 54 in base 7 are 1, 0 and 5. 5 > 3 so it's replaced by -2. The digits then are 1, 0 and -2 giving a(54) = 1*7^2 + 0 * 7^1 + (-2) * 7^0 = 49 + 0 - 2 = 47. - _David A. Corneth_, Aug 26 2019
		

Crossrefs

Column k=3 of A319047.

Programs

  • Maple
    a:= proc(n) option remember; `if`(n=0, 0,
          7*a(iquo(n, 7))+mods(n, 7))
        end:
    seq(a(n), n=0..100);  # Alois P. Heinz, Aug 26 2019
  • PARI
    a(n,b=7) = fromdigits(apply(d -> if (dRémy Sigrist, Aug 26 2019
    
  • PARI
    a(n) = my(d = digits(n, 7)); for(i = 1, #d, if(d[i] > 3, d[i]-=7)); fromdigits(d, 7) \\ David A. Corneth, Aug 26 2019

A316823 Balanced nonary enumeration (or balanced nonary representation) of integers; write n in nonary (base 9) and then replace 5's with (-4)'s, 6's with (-3)'s, 7's with (-2)'s, and 8's with (-1)'s.

Original entry on oeis.org

0, 1, 2, 3, 4, -4, -3, -2, -1, 9, 10, 11, 12, 13, 5, 6, 7, 8, 18, 19, 20, 21, 22, 14, 15, 16, 17, 27, 28, 29, 30, 31, 23, 24, 25, 26, 36, 37, 38, 39, 40, 32, 33, 34, 35, -36, -35, -34, -33, -32, -40, -39, -38, -37, -27, -26, -25, -24, -23, -31, -30, -29, -28
Offset: 0

Author

Jackson Haselhorst, Aug 26 2019

Keywords

Examples

			Since 35_10=38_9, the digits of 35 in base 9 are 3 and 8. 8>4, so it is replaced with (-1). The digits are then 3 and -1, so a(35)=3*9^1+(-1)*9^0=27-1=26.
		

Crossrefs

Column k=4 of A319047.

Programs

  • Maple
    a:= proc(n) option remember; `if`(n=0, 0,
          9*a(iquo(n, 9))+mods(n, 9))
        end:
    seq(a(n), n=0..100);  # Alois P. Heinz, Aug 26 2019
  • PARI
    f(x) = if (x > 9/2, -(9-x), x);
    a(n) = subst(Pol(apply(x->f(x), digits(n, 9)), 'x), 'x, 9); \\ Michel Marcus, Aug 27 2019
Showing 1-4 of 4 results.