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.

This page as a plain text file.
%I A165413 #30 Jan 04 2021 17:03:55
%S A165413 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,
%T A165413 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,
%U A165413 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
%N A165413 a(n) is the number of distinct lengths of runs in the binary representation of n.
%C A165413 Least k whose value is n: 1, 4, 35, 536, 16775, 1060976, ..., = A165933. - _Robert G. Wilson v_, Sep 30 2009
%H A165413 Reinhard Zumkeller, <a href="/A165413/b165413.txt">Table of n, a(n) for n = 1..10000</a>
%F A165413 a(n) = 1 for n in A140690. - _Robert G. Wilson v_, Sep 30 2009
%e A165413 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.
%t A165413 f[n_] := Length@ Union@ Map[ Length, Split@ IntegerDigits[n, 2]]; Array[f, 105] (* _Robert G. Wilson v_, Sep 30 2009 *)
%o A165413 (Haskell)
%o A165413 import Data.List (group, nub)
%o A165413 a165413 = length . nub . map length . group . a030308_row
%o A165413 -- _Reinhard Zumkeller_, Mar 02 2013
%o A165413 (PARI)
%o A165413 binruns(n) = {
%o A165413   if (n == 0, return([1, 0]));
%o A165413   my(bag = List(), v=0);
%o A165413   while(n != 0,
%o A165413         v = valuation(n,2); listput(bag, v); n >>= v; n++;
%o A165413         v = valuation(n,2); listput(bag, v); n >>= v; n--);
%o A165413   return(Vec(bag));
%o A165413 };
%o A165413 a(n) = #Set(select(k->k, binruns(n)));
%o A165413 vector(105, i, a(i))  \\ _Gheorghe Coserea_, Sep 17 2015
%o A165413 (Python)
%o A165413 from itertools import groupby
%o A165413 def a(n): return len(set([len(list(g)) for k, g in groupby(bin(n)[2:])]))
%o A165413 print([a(n) for n in range(1, 106)]) # _Michael S. Branicky_, Jan 04 2021
%Y A165413 Cf. A140690 (locations of 1's), A165933 (locations of new highs).
%Y A165413 Cf. A005811, A165414.
%Y A165413 Cf. A030308, A044813.
%K A165413 base,nonn
%O A165413 1,4
%A A165413 _Leroy Quet_, Sep 17 2009
%E A165413 More terms from _Robert G. Wilson v_, Sep 30 2009