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.

A346688 Replace 4^k with (-1)^k in base-4 expansion of n.

Original entry on oeis.org

0, 1, 2, 3, -1, 0, 1, 2, -2, -1, 0, 1, -3, -2, -1, 0, 1, 2, 3, 4, 0, 1, 2, 3, -1, 0, 1, 2, -2, -1, 0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, -1, 0, 1, 2, 3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, -1, 0, 1, 2, -2, -1, 0, 1, -3, -2, -1, 0, -4, -3, -2, -1, 0, 1, 2, 3, -1, 0, 1, 2, -2, -1, 0, 1, -3, -2, -1, 0, 1, 2, 3, 4, 0, 1, 2, 3, -1
Offset: 0

Views

Author

Ilya Gutkovskiy, Jul 29 2021

Keywords

Comments

If n has base-4 expansion abc..xyz with least significant digit z, a(n) = z - y + x - w + ...

Examples

			54 = 312_4, 2 - 1 + 3 = 4, so a(54) = 4.
		

Crossrefs

Programs

  • Mathematica
    nmax = 104; A[] = 0; Do[A[x] = x (1 + 2 x + 3 x^2)/(1 - x^4) - (1 + x + x^2 + x^3) A[x^4] + O[x]^(nmax + 1) // Normal, nmax + 1]; CoefficientList[A[x], x]
    Table[n + 5 Sum[(-1)^k Floor[n/4^k], {k, 1, Floor[Log[4, n]]}], {n, 0, 104}]
  • Python
    from sympy.ntheory.digits import digits
    def a(n):
        return sum(bi*(-1)**k for k, bi in enumerate(digits(n, 4)[1:][::-1]))
    print([a(n) for n in range(105)]) # Michael S. Branicky, Jul 29 2021

Formula

G.f. A(x) satisfies: A(x) = x * (1 + 2*x + 3*x^2) / (1 - x^4) - (1 + x + x^2 + x^3) * A(x^4).
a(n) = n + 5 * Sum_{k>=1} (-1)^k * floor(n/4^k).