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.

A049502 Major index of n, 2nd definition.

This page as a plain text file.
%I A049502 #33 Jan 30 2023 12:44:07
%S A049502 0,0,0,0,0,1,0,0,0,1,2,2,0,1,0,0,0,1,2,2,3,4,3,3,0,1,2,2,0,1,0,0,0,1,
%T A049502 2,2,3,4,3,3,4,5,6,6,4,5,4,4,0,1,2,2,3,4,3,3,0,1,2,2,0,1,0,0,0,1,2,2,
%U A049502 3,4,3,3,4,5,6,6,4,5,4,4,5,6,7,7,8,9,8,8,5,6,7,7,5,6,5,5,0,1,2,2,3,4,3,3,4
%N A049502 Major index of n, 2nd definition.
%C A049502 a(A023758(n)) = 0; a(A101082(n)) > 0. - _Reinhard Zumkeller_, Jun 17 2015
%D A049502 D. M. Bressoud, Proofs and Confirmations, Camb. Univ. Press, 1999; cf. p. 89.
%H A049502 Lars Blomberg, <a href="/A049502/b049502.txt">Table of n, a(n) for n = 0..10000</a>
%F A049502 Write n in binary; add positions where there are 1's followed by 0's, counting from right.
%e A049502 83 = 1010011 has 1's followed by 0's in positions 2 and 5 (reading from the right), so a(83)=7.
%p A049502 A049502 := proc(n)
%p A049502     local a,ndgs,p ;
%p A049502     a := 0 ;
%p A049502     ndgs := convert(n,base,2) ;
%p A049502     for p from 1 to nops(ndgs)-1 do
%p A049502         if op(p,ndgs)- op(p+1,ndgs) = 1 then
%p A049502             a := a+p ;
%p A049502         end if;
%p A049502     end do:
%p A049502     a ;
%p A049502 end proc: # _R. J. Mathar_, Oct 17 2012
%t A049502 Table[Total[Flatten[Position[Partition[Reverse[IntegerDigits[n,2]],2,1],_?(#=={1,0}&)]]],{n,0,110}] (* _Harvey P. Dale_, Oct 05 2013 *)
%t A049502 Table[Total[SequencePosition[Reverse[IntegerDigits[n,2]],{1,0}][[All,1]]],{n,0,120}] (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Nov 26 2020 *)
%o A049502 (Haskell)
%o A049502 a049502 = f 0 1 where
%o A049502    f m i x = if x <= 4
%o A049502                 then m else f (if mod x 4 == 1
%o A049502                                   then m + i else m) (i + 1) $ div x 2
%o A049502 -- _Reinhard Zumkeller_, Jun 17 2015
%o A049502 (Python)
%o A049502 def m(n):
%o A049502     x=bin(int(n))[2:][::-1]
%o A049502     s=0
%o A049502     for i in range(1,len(x)):
%o A049502         if x[i-1]=="1" and x[i]=="0":
%o A049502             s+=i
%o A049502     return s
%o A049502 for i in range(101):
%o A049502     print(str(i)+" "+str(m(i))) # _Indranil Ghosh_, Dec 22 2016
%o A049502 (PARI) a(n)=if(n<5, return(0)); sum(i=0,exponent(n)-1, (bittest(n,i) && !bittest(n,i+1))*(i+1)) \\ _Charles R Greathouse IV_, Jan 30 2023
%Y A049502 Cf. A049501, A037800.
%Y A049502 Cf. A023758, A101082.
%K A049502 nonn,base,nice,easy
%O A049502 0,11
%A A049502 _N. J. A. Sloane_
%E A049502 More terms from _Erich Friedman_, Feb 19 2000