OFFSET
1,2
COMMENTS
LINKS
FORMULA
EXAMPLE
The first terms, in decimal and in binary, are:
n a(n) bin(n) bin(a(n))
-- ---- ------ ---------
1 1 1 1
2 6 10 110
3 3 11 11
4 14 100 1110
5 29 101 11101
6 28 110 11100
7 7 111 111
8 30 1000 11110
9 123 1001 1111011
10 122 1010 1111010
11 61 1011 111101
12 60 1100 111100
13 121 1101 1111001
14 120 1110 1111000
15 15 1111 1111
PROG
(PARI) toruns(n) = { my (r=[]); while (n, my (v=valuation(n+n%2, 2)); n\=2^v; r=concat(v, r)); r }
fromruns(r) = { my (v=0); for (k=1, #r, v=(v+k%2)*2^r[k]-k%2); v }
a(n) = { my (r=toruns(n)); fromruns(concat(vecsum(r), r[1..#r-1])) }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Rémy Sigrist, Feb 18 2021
STATUS
approved