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.

A281497 Write n in binary reflected Gray code and sum the positions where there is a '1' followed immediately to the left by a '0', counting the rightmost digit as position 1.

This page as a plain text file.
%I A281497 #11 May 22 2025 10:21:45
%S A281497 0,0,0,0,0,1,0,0,1,0,0,2,2,1,0,0,1,2,2,0,0,1,0,3,4,3,3,2,2,1,0,0,1,2,
%T A281497 2,3,3,4,3,0,1,0,0,2,2,1,0,4,5,6,6,4,4,5,4,3,4,3,3,2,2,1,0,0,1,2,2,3,
%U A281497 3,4,3,4,5,4,4,6,6,5,4,0,1,2,2,0,0,1,0,3,4,3,3,2,2,1,0,5,6,7,7,8,8,9,8,5,6,5,5,7,7,6
%N A281497 Write n in binary reflected Gray code and sum the positions where there is a '1' followed immediately to the left by a '0', counting the rightmost digit as position 1.
%H A281497 Indranil Ghosh, <a href="/A281497/b281497.txt">Table of n, a(n) for n = 1..10000</a>
%F A281497 a(n) = A049502(A003188(n)).
%e A281497 For n = 12, the binary reflected Gray code for 12 is '1010'. In '1010', the position of '1' followed immediately to the left by a '0' counting from right is 2. So, a(12) = 2.
%t A281497 Table[If[Length@ # == 0, 0, Total[#[[All, 1]]]] &@ SequencePosition[ Reverse@ IntegerDigits[#, 2] &@ BitXor[n, Floor[n/2]], {1, 0}], {n, 120}] (* _Michael De Vlieger_, Jan 23 2017, Version 10.1, after _Robert G. Wilson v_ at A003188 *)
%o A281497 (Python)
%o A281497 def G(n):
%o A281497     return bin(n^(n/2))[2:]
%o A281497 def a(n):
%o A281497     x=G(n)[::-1]
%o A281497     s=0
%o A281497     for i in range(1,len(x)):
%o A281497         if x[i-1]=="1" and x[i]=="0":
%o A281497             s+=i
%o A281497     return s
%Y A281497 Cf. A003188, A014550, A049502, A281388.
%K A281497 nonn,base
%O A281497 1,12
%A A281497 _Indranil Ghosh_, Jan 23 2017