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.

A165413 a(n) is the number of distinct lengths of runs in the binary representation of n.

Original entry on oeis.org

1, 1, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 1, 2, 2, 2, 2, 2, 2, 3, 2, 1, 2, 2, 2, 3, 1, 3, 2, 3, 2, 2, 2, 1, 2, 2, 2, 3, 3, 2, 3, 2, 3, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 2, 1, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 2, 3, 2
Offset: 1

Views

Author

Leroy Quet, Sep 17 2009

Keywords

Comments

Least k whose value is n: 1, 4, 35, 536, 16775, 1060976, ..., = A165933. - Robert G. Wilson v, Sep 30 2009

Examples

			92 in binary is 1011100. There is a run of one 1, followed by a run of one 0, then a run of three 1's, then finally a run of two 0's. The run lengths are therefore (1,1,3,2). The distinct values of these run lengths are (1,3,2). Since there are 3 distinct values, then a(92) = 3.
		

Crossrefs

Cf. A140690 (locations of 1's), A165933 (locations of new highs).

Programs

  • Haskell
    import Data.List (group, nub)
    a165413 = length . nub . map length . group . a030308_row
    -- Reinhard Zumkeller, Mar 02 2013
    
  • Mathematica
    f[n_] := Length@ Union@ Map[ Length, Split@ IntegerDigits[n, 2]]; Array[f, 105] (* Robert G. Wilson v, Sep 30 2009 *)
  • PARI
    binruns(n) = {
      if (n == 0, return([1, 0]));
      my(bag = List(), v=0);
      while(n != 0,
            v = valuation(n,2); listput(bag, v); n >>= v; n++;
            v = valuation(n,2); listput(bag, v); n >>= v; n--);
      return(Vec(bag));
    };
    a(n) = #Set(select(k->k, binruns(n)));
    vector(105, i, a(i))  \\ Gheorghe Coserea, Sep 17 2015
    
  • Python
    from itertools import groupby
    def a(n): return len(set([len(list(g)) for k, g in groupby(bin(n)[2:])]))
    print([a(n) for n in range(1, 106)]) # Michael S. Branicky, Jan 04 2021

Formula

a(n) = 1 for n in A140690. - Robert G. Wilson v, Sep 30 2009

Extensions

More terms from Robert G. Wilson v, Sep 30 2009