login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

An even-odd sequence: a(n) = n/2 if n is even, or a(n-1) + 2^floor(log_2(n+1)) otherwise.
0

%I #16 Dec 07 2019 00:47:07

%S 0,2,1,5,2,6,3,11,4,12,5,13,6,14,7,23,8,24,9,25,10,26,11,27,12,28,13,

%T 29,14,30,15,47,16,48,17,49,18,50,19,51,20,52,21,53,22,54,23,55,24,56,

%U 25,57,26,58,27,59,28,60,29,61,30,62,31,95,32,96,33,97,34,98,35,99,36,100

%N An even-odd sequence: a(n) = n/2 if n is even, or a(n-1) + 2^floor(log_2(n+1)) otherwise.

%t a[0] = 0; a[n_] := a[n] = If[Mod[n, 2] == 0, n/2, a[n - 1] + 2^(Floor[Log[2, 1 + n]])]; Table[a[n], {n, 0, 100}]

%t nxt[{n_,a_}]:={n+1,If[EvenQ[n+1],(n+1)/2,a+2^Floor[Log[2,n+2]]]}; Transpose[ NestList[ nxt,{0,0},100]][[2]] (* _Harvey P. Dale_, Feb 26 2013 *)

%o (PARI) a(n)=n\2+if(n%2,2^(log(n+1.5)\log(2))) \\ _Charles R Greathouse IV_, Jan 30 2012

%K nonn,less,easy

%O 0,2

%A _Roger L. Bagula_ and _Gary W. Adamson_, Sep 27 2008