OFFSET
0,2
COMMENTS
This is a self-inverse permutation of the nonnegative integers.
Clarification: The consecutive "runs" (mentioned in the definition) alternate between those completely of 1's and those completely of 0's.
In the binary representation of n, replace each run of length r by a run of length A014681(r). - Rémy Sigrist, Oct 09 2018
LINKS
FORMULA
EXAMPLE
152 in binary is 10011000. There is a run of one 1, followed by a run of two 0's, followed by a run of two 1's, followed by a run of three 0's. We reduce the two runs of two digits each to one digit; and we add a digit (a 1) to the first run of one 1, and a digit (a 0) to the last run of three 0's, to get 11010000. So a(152) is the decimal equivalent of this, which is 208.
MAPLE
rerun := proc(L) if nops(L) mod 2 = 0 then subsop(1=NULL, L) ; else [op(L), op(1, L)] ; fi; end: Lton := proc(L) local i; add( op(i, L)*2^(i-1), i=1..nops(L)) ; end: A162853 := proc(n) local strt, en, L, dgs, i; strt := 1; en := -1; L := [] ; dgs := convert(n, base, 2) ; for i from 2 to nops(dgs) do if op(i, dgs) <> op(i-1, dgs) then en := i-1 ; L := [op(L), op(rerun([op(strt..en, dgs)])) ] ; strt := i; fi; od: en := nops(dgs) ; L := [op(L), op(rerun([op(strt..en, dgs)])) ] ; Lton(L) ; end: seq(A162853(n), n=1..100) ; # R. J. Mathar, Aug 01 2009
MATHEMATICA
Table[FromDigits[Flatten[If[OddQ[Length[#]], Join[{First[#]}, #], Drop[#, 1]]& /@Split[ IntegerDigits[ n, 2]]], 2], {n, 70}] (* Harvey P. Dale, Jun 20 2011 *)
PROG
(PARI) a(n) = if (n==0, 0, my (b=n%2, r=valuation(n+b, 2), rr=if (r%2, r+1, r-1)); (a(n\2^r)+b)*2^rr-b) \\ Rémy Sigrist, Oct 09 2018
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Leroy Quet, Jul 14 2009
EXTENSIONS
Extended beyond a(13) by R. J. Mathar, Aug 01 2009
a(0) added by Rémy Sigrist, Oct 09 2018
STATUS
approved