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.

A356352 a(n) = GCD of run lengths in binary expansion of n.

Original entry on oeis.org

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

Views

Author

Rémy Sigrist, Oct 15 2022

Keywords

Comments

a(0) = 0 as the GCD of an empty list (we consider here that the binary expansion of 0 has no runs).

Crossrefs

Programs

  • Mathematica
    {0}~Join~Array[GCD @@ Map[Length, Split@ IntegerDigits[#, 2]] &, 104] (* Michael De Vlieger, Oct 17 2022 *)
  • PARI
    a(n) = { my (r=[]); while (n, my (v=valuation(n+n%2, 2)); n\=2^v; r=concat(v, r)); gcd(r) }
    
  • Python
    from math import gcd
    from itertools import groupby
    def a(n):
        if n == 0: return 0 # by convention
        return gcd(*(len(list(g)) for k, g in groupby(bin(n)[2:])))
    print([a(n) for n in range(87)]) # Michael S. Branicky, Oct 15 2022

Formula

a(A001196(n)) = 2*a(n).
a(2^k-1) = k for any k >= 0.