OFFSET
0,3
COMMENTS
Define the "blocks" of the binary expansion of n as runs of 0's followed by a 1 bit and additionally followed with a 0 bit if it lies immediately after the 1 bit. For example, the blocks in 45986 (shown in parentheses) are 1(01)1(001)11(010)(0010). To obtain binary expansion of a(n) from binary expansion of n, move the rightmost bit in each block to the position after leftmost bit in the same block and leave all other 1 bits unchanged (see the Example).
LINKS
FORMULA
EXAMPLE
For n = 45986, moves are in each (...) block
n = 45986 = binary 1(01)1(001)11(010)(0010)
a(n) = 46481 = binary 1(01)1(010)11(001)(0001)
We have moves in last 3 blocks, while in the first block the rightmost 1 bit is already lies on the position after leftmost bit in block, so we have no change in this case.
PROG
(PARI) a(n) = my(v1); v1 = binary(n); my(A = 1); while(A <= #v1, while(A <= #v1 && v1[A], A++); my(B = A); while((A + 1) <= #v1 && !v1[A + 1], A++); if(A < #v1, if((A + 2) <= #v1 && !v1[A + 2], B = A; A++); v1[A + 1] = !v1[A + 1]; v1[B + 1] = !v1[B + 1]); A += 2); fromdigits(v1, 2)
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Mikhail Kurkov, Nov 13 2023
STATUS
approved