login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A165413 a(n) is the number of distinct lengths of runs in the binary representation of n. 30

%I #30 Jan 04 2021 17:03:55

%S 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 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 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 a(n) is the number of distinct lengths of runs in the binary representation of n.

%C Least k whose value is n: 1, 4, 35, 536, 16775, 1060976, ..., = A165933. - _Robert G. Wilson v_, Sep 30 2009

%H Reinhard Zumkeller, <a href="/A165413/b165413.txt">Table of n, a(n) for n = 1..10000</a>

%F a(n) = 1 for n in A140690. - _Robert G. Wilson v_, Sep 30 2009

%e 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 f[n_] := Length@ Union@ Map[ Length, Split@ IntegerDigits[n, 2]]; Array[f, 105] (* _Robert G. Wilson v_, Sep 30 2009 *)

%o (Haskell)

%o import Data.List (group, nub)

%o a165413 = length . nub . map length . group . a030308_row

%o -- _Reinhard Zumkeller_, Mar 02 2013

%o (PARI)

%o binruns(n) = {

%o if (n == 0, return([1, 0]));

%o my(bag = List(), v=0);

%o while(n != 0,

%o v = valuation(n,2); listput(bag, v); n >>= v; n++;

%o v = valuation(n,2); listput(bag, v); n >>= v; n--);

%o return(Vec(bag));

%o };

%o a(n) = #Set(select(k->k, binruns(n)));

%o vector(105, i, a(i)) \\ _Gheorghe Coserea_, Sep 17 2015

%o (Python)

%o from itertools import groupby

%o def a(n): return len(set([len(list(g)) for k, g in groupby(bin(n)[2:])]))

%o print([a(n) for n in range(1, 106)]) # _Michael S. Branicky_, Jan 04 2021

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

%Y Cf. A005811, A165414.

%Y Cf. A030308, A044813.

%K base,nonn

%O 1,4

%A _Leroy Quet_, Sep 17 2009

%E More terms from _Robert G. Wilson v_, Sep 30 2009

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 19 13:40 EDT 2024. Contains 371792 sequences. (Running on oeis4.)