OFFSET
1,2
COMMENTS
LINKS
Andrew Howroyd, Table of n, a(n) for n = 1..10000
FORMULA
a(n) = 2*a(n/2)-1 if n=2^k else a(n)=a(2^k-n+1)+n-2^(k-1) if 2^(k-1)<n<2^k. (Ed.)
EXAMPLE
The sequence begins 1, 2, then reverse 1, 2 = 2, 1 then add 1, 2 to the latter getting 3, 3. Then append 3, 3, to the right of 1, 2, getting 1, 2, 3, 3. Then repeating the instructions, 1, 2, 3, 3 is reversed then add 1, 2, 3, 4 to 3, 3, 2, 1, = 4, 5, 5, 5. Append the latter to 1, 2, 3, 3 getting 1, 2, 3, 3, 4, 5, 5, 5, ...; and so on.
MATHEMATICA
Nest[Join[#, Range[Length[#]] + Reverse[#]] &, {1}, 7] (* Paolo Xausa, Sep 24 2025 *)
PROG
(PARI) a(n)=my(k=logint(n, 2)); if(n<=2, n, if(n==2^k, 2*a(n/2)-1, a(2^(k+1)-n+1)+n-2^k)) \\ Andrew Howroyd, Sep 24 2025
CROSSREFS
KEYWORD
nonn
AUTHOR
Gary W. Adamson, Sep 19 2003
EXTENSIONS
Edited by John W. Layman, Oct 10 2003
a(65) onwards from Andrew Howroyd, Sep 24 2025
STATUS
approved
