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 A266151 #12 Jan 20 2019 23:19:02 %S A266151 0,3,6,1,12,27,2,15,24,51,54,13,4,11,30,7,48,99,102,25,108,219,26,111, %T A266151 8,19,22,5,60,123,14,63,96,195,198,49,204,411,50,207,216,435,438,109, %U A266151 52,107,222,55,16,35,38,9,44,91,10,47,120,243,246,61,28,59,126,31 %N A266151 Take the binary representation of n, increase each run of 1's by one 1 if the length of run is odd, otherwise, if length of run is even, remove one 1. a(n) is the decimal equivalent of the result. %C A266151 This is a self-inverse permutation of the positive integers. %H A266151 Rémy Sigrist, <a href="/A266151/b266151.txt">Table of n, a(n) for n = 0..8192</a> %H A266151 <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a> %e A266151 a(4) = 12 since 4 = 100 binary -> 1100 = 12 decimal, %e A266151 a(5) = 27 since 5 = 101 binary -> 110011 = 27 decimal, %e A266151 a(6) = 2 since 6 = 110 binary -> 10 = 2 decimal. %t A266151 Table[FromDigits[#, 2] &@ Flatten[If[First@ # == 1, If[OddQ@ Length@ #, Append[IntegerDigits@ #, 1], Most@ IntegerDigits@ #], #] & /@ Split@ IntegerDigits[n, 2]], {n, 63}] (* _Michael De Vlieger_, Dec 22 2015 *) %o A266151 (PARI) a(n) = if (n==0, 0, my (b=n%2, r=valuation(n+b, 2), rr=if (b==0, r, r%2, r+1, r-1)); (a(n\2^r)+b)*2^rr-b) \\ _Rémy Sigrist_, Jan 20 2019 %Y A266151 Cf. A007088, A084483, A162853, A175046, A175047, A175048, A266150. %K A266151 nonn,base %O A266151 0,2 %A A266151 _Alex Ratushnyak_, Dec 21 2015 %E A266151 a(0) = 0 prepended by _Rémy Sigrist_, Jan 20 2019