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.
%I A003188 M2250 #185 May 13 2025 15:01:05 %S A003188 0,1,3,2,6,7,5,4,12,13,15,14,10,11,9,8,24,25,27,26,30,31,29,28,20,21, %T A003188 23,22,18,19,17,16,48,49,51,50,54,55,53,52,60,61,63,62,58,59,57,56,40, %U A003188 41,43,42,46,47,45,44,36,37,39,38,34,35,33,32,96,97,99,98,102,103,101 %N A003188 Decimal equivalent of Gray code for n. %C A003188 Inverse of sequence A006068 considered as a permutation of the nonnegative integers, i.e., A006068(A003188(n)) = n = A003188(A006068(n)). - _Howard A. Landman_, Sep 25 2001 %C A003188 Restricts to a permutation of each {2^(i - 1) .. 2^i - 1}. - _Jason Kimberley_, Apr 02 2012 %C A003188 a(n) mod 2 = floor(((n + 1) mod 4) / 2), see also A021913. - _Reinhard Zumkeller_, Apr 28 2012 %C A003188 Invented by Emile Baudot (1845-1903), originally called a "cyclic-permuted" code. Gray codes are named after Frank Gray, who patented their use for shaft encoders in 1953. [F. Gray, "Pulse Code Communication", U.S. Patent 2,632,058, March 17, 1953.] - _Robert G. Wilson v_, Jun 22 2014 %C A003188 For n >= 2, let G_n be the graph whose vertices are labeled as 0,1,...,2^n-1, and two vertices are adjacent if and only if their binary expansions differ in exactly one bit, then a(0),a(1),...,a(2^n-1),a(0) is a Hamilton cycle in G_n. - _Jianing Song_, Jun 01 2022 %D A003188 M. Gardner, Mathematical Games, Sci. Amer. Vol. 227 (No. 2, Feb. 1972), p. 107. %D A003188 M. Gardner, Knotted Doughnuts and Other Mathematical Entertainments. Freeman, NY, 1986, p. 15. %D A003188 N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence). %H A003188 Indranil Ghosh, <a href="/A003188/b003188.txt">Table of n, a(n) for n = 0..32767</a> (first 1001 terms from N. J. A. Sloane) %H A003188 M. W. Bunder, K. P. Tognetti, and G. E. Wheeler, <a href="http://dx.doi.org/10.1016/j.disc.2006.12.004">On binary reflected Gray codes and functions</a>, Discr. Math., 308 (2008), 1690-1700. %H A003188 Hsien-Kuei Hwang, S. Janson, and T.-H. Tsai, <a href="http://140.109.74.92/hk/wp-content/files/2016/12/aat-hhrr-1.pdf">Exact and asymptotic solutions of the recurrence f(n) = f(floor(n/2)) + f(ceiling(n/2)) + g(n): theory and applications</a>, Preprint 2016. %H A003188 Hsien-Kuei Hwang, S. Janson, and T.-H. Tsai, <a href="https://doi.org/10.1145/3127585">Exact and Asymptotic Solutions of a Divide-and-Conquer Recurrence Dividing at Half: Theory and Applications</a>, ACM Transactions on Algorithms, 13:4 (2017), #47; DOI: 10.1145/3127585. %H A003188 Hsien-Kuei Hwang, Svante Janson, and Tsung-Hsi Tsai, <a href="https://arxiv.org/abs/2210.10968">Identities and periodic oscillations of divide-and-conquer recurrences splitting at half</a>, arXiv:2210.10968 [cs.DS], 2022, p. 39. %H A003188 P. Mathonet, M. Rigo, M. Stipulanti and N. Zénaïdi, <a href="https://arxiv.org/abs/2201.06636">On digital sequences associated with Pascal's triangle</a>, arXiv:2201.06636 [math.NT], 2022. %H A003188 J. A. Oteo and J. Ros, <a href="http://dx.doi.org/10.1088/0305-4470/38/41/007">A Fractal Set from the Binary Reflected Gray Code</a>, J. Phys. A: Math Gen. 38 (2005) 8935-8949. %H A003188 Ed Pegg, Jr., <a href="http://www.mathpuzzle.com/MAA/07-Sequence%20Pictures/mathgames_12_08_03.html">Sequence Pictures</a>, Math Games column, Dec 08 2003. %H A003188 Ed Pegg, Jr., <a href="/A000043/a000043_2.pdf">Sequence Pictures</a>, Math Games column, Dec 08 2003 [Cached copy, with permission (pdf only)] %H A003188 Ralf Stephan, <a href="/somedcgf.html">Some divide-and-conquer sequences ...</a> %H A003188 Ralf Stephan, <a href="/A079944/a079944.ps">Table of generating functions</a> %H A003188 Paul Tarau, <a href="http://logic.csci.unt.edu/tarau/research/2009/fISO.pdf">Isomorphic Data Encodings and their Generalization to Hylomorphisms on Hereditarily Finite Data Types</a> %H A003188 Pierluigi Vellucci and Alberto Maria Bersani, <a href="http://arxiv.org/abs/1604.00222">Ordering of nested square roots of 2 according to Gray code</a>, arXiv:1604.00222 [math.NT], 2016. %H A003188 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a> %F A003188 a(n) = 2*a(floor(n/2)) + A021913(n - 1). - _Henry Bottomley_, Apr 05 2001 %F A003188 a(n) = n XOR floor(n/2), where XOR is the binary exclusive OR operator. - _Paul D. Hanna_, Jun 04 2002 %F A003188 G.f.: (1/(1-x)) * Sum_{k>=0} 2^k*x^2^k/(1 + x^2^(k+1)). - _Ralf Stephan_, May 06 2003 %F A003188 a(0) = 0, a(2n) = 2a(n) + [n odd], a(2n + 1) = 2a(n) + [n even]. - _Ralf Stephan_, Oct 20 2003 %F A003188 a(0) = 0, a(n) = 2 a(floor(n/2)) + mod(floor((n + 1)/2), 2). %F A003188 a(n) = Sum_{k=1..n} 2^A007814(k) * (-1)^((k/2^A007814(k) - 1)/2). - _Ralf Stephan_, Oct 29 2003 %F A003188 a(0) = 0, a(n + 1) = a(n) XOR 2^A007814(n) - Jaume Simon Gispert (jaume(AT)nuem.com), Sep 11 2004 %F A003188 Inverse of sequence A006068. - _Philippe Deléham_, Apr 29 2005 %F A003188 a(n) = a(n-1) XOR A006519(n). - _Franklin T. Adams-Watters_, Jul 18 2011 %F A003188 From _Mikhail Kurkov_, Sep 27 2023: (Start) %F A003188 a(2^m + k) = a(2^m - k - 1) + 2^m for 0 <= k < 2^m, m >= 0. %F A003188 a(n) = a(A053645(A054429(n))) + A053644(n) for n > 0. %F A003188 a(n) = A063946(a(A053645(n)) + A053644(n)) for n > 0. (End) %e A003188 For n = 13, the binary reflected Gray code representation of n is '1011' and 1011_2 = 11_10. So, a(13) = 11. - _Indranil Ghosh_, Jan 23 2017 %p A003188 with(combinat); graycode(6); # to produce first 64 terms %p A003188 printf(cat(` %.6d`$64), op(map(convert, graycode(6), binary))); lprint(); # to produce binary strings %p A003188 # alternative: %p A003188 read("transforms"): %p A003188 A003188 := proc(n) %p A003188 XORnos(n,floor(n/2)) ; %p A003188 end proc: # _R. J. Mathar_, Mar 09 2015 %p A003188 # another Maple program: %p A003188 a:= n-> Bits[Xor](n, iquo(n, 2)): %p A003188 seq(a(n), n=0..70); # _Alois P. Heinz_, Aug 16 2020 %t A003188 f[n_] := BitXor[n, Floor[n/2]]; Array[f, 70, 0] (* _Robert G. Wilson v_, Jun 09 2010 *) %o A003188 (PARI) a(n)=bitxor(n,n>>1); %o A003188 (PARI) a(n)=sum(k=1,n,(-1)^((k/2^valuation(k,2)-1)/2)*2^valuation(k,2)) %o A003188 (C) int a(int n) { return n ^ (n>>1); } %o A003188 (Magma) // A recursive algorithm %o A003188 N := 10; s := [[]]; %o A003188 for n in [1..N] do %o A003188 for j in [#s..1 by -1] do %o A003188 Append(~s,Append(s[j],1)); %o A003188 Append(~s[j],0); %o A003188 end for; %o A003188 end for; %o A003188 [SequenceToInteger(b,2):b in s]; // _Jason Kimberley_, Apr 02 2012 %o A003188 (Magma) // A direct algorithm %o A003188 I2B := func< i | [b eq 1: b in IntegerToSequence(i,2)]>; %o A003188 B2I := func< s | SequenceToInteger([b select 1 else 0:b in s],2)>; %o A003188 [B2I(Xor(I2B(i),I2B(i div 2)cat[false])):i in [1..127]]; //_Jason Kimberley_, Apr 02 2012 %o A003188 (Haskell) %o A003188 import Data.Bits (xor, shiftR) %o A003188 a003188 n = n `xor` (shiftR n 1) :: Integer %o A003188 -- _Reinhard Zumkeller_, May 26 2013, Apr 28 2012 %o A003188 (Python) %o A003188 def A003188(n): %o A003188 return int(bin(n^(n//2))[2:],2) # _Indranil Ghosh_, Jan 23 2017 %o A003188 (Python) %o A003188 def A003188(n): return n^ n>>1 # _Chai Wah Wu_, Jun 29 2022 %o A003188 (R) %o A003188 maxn <- 63 # by choice %o A003188 a <- 1 %o A003188 for(n in 1:maxn){ a[2*n ] <- 2*a[n] + (n%%2 != 0) %o A003188 a[2*n+1] <- 2*a[n] + (n%%2 == 0)} %o A003188 (a <- c(0,a)) %o A003188 # _Yosu Yurramendi_, Apr 10 2020 %o A003188 (C#) %o A003188 static uint a(this uint n) => (n >> 1) ^ n; // _Frank Hollstein_, Mar 12 2021 %Y A003188 a(2*A003714(n)) = 3*A003714(n) for all n. - _Antti Karttunen_, Apr 26 1999 %Y A003188 Cf. A014550 (in binary), A055975 (first differences), A048724 (even bisection), A065621 (odd bisection). %Y A003188 Cf. A006068, A038554, A048641, A048642. %K A003188 nonn,nice,easy,look %O A003188 0,3 %A A003188 _N. J. A. Sloane_