login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 


Define a(1)=2 and a(2)=3. Then, if a(n-2) and a(n-1) have the same parity, a(n)=(a(n-2)+a(n-1))/2; if not, a(n)=a(n-2)/2+a(n-1) for a(n-2) even or a(n)=a(n-2)+a(n-1)/2 for a(n-1) even.
3

%I #37 Mar 29 2015 23:02:46

%S 2,3,4,5,7,6,10,8,9,13,11,12,17,23,20,33,43,38,62,50,56,53,81,67,74,

%T 104,89,141,115,128,179,243,211,227,219,223,221,222,332,277,443,360,

%U 623,803,713,758,1092,925,1471,1198,2070,1634,1852,1743,2669,2206,3772

%N Define a(1)=2 and a(2)=3. Then, if a(n-2) and a(n-1) have the same parity, a(n)=(a(n-2)+a(n-1))/2; if not, a(n)=a(n-2)/2+a(n-1) for a(n-2) even or a(n)=a(n-2)+a(n-1)/2 for a(n-1) even.

%C If we start with a(1)=a(2)=2, then a(n)=2 for every n.

%C As N increases, sum_{n=1..N} 1/a(n) converges quickly to

%C 2.6332482094949767034995557279162460374965915768...

%C More generally, if one starts with a(1) = a(2), then a(n) = a(1) for every n.

%H Pierre CAMI, <a href="/A254498/b254498.txt">Table of n, a(n) for n = 1..1000</a>

%e As 2 is even and 3 is odd, a(4) = 2/2 + 3 = 4.

%e As 3 is odd and 4 is even, a(5) = 3 + 4/2 = 5.

%t a[n_] := a[n] = If[ Mod[ a[n - 1], 2] == Mod[ a[n - 2], 2], (a[n - 1] + a[n - 2])/2, If[ OddQ@ a[n - 1], a[n - 1] + a[n - 2]/2, a[n - 1]/2 + a[n - 2]]]; a[1] = 2; a[2] = 3; a = Array[a, 69] (* _Robert G. Wilson v_, Mar 11 2015 *)

%o (PFGW & SCRIPT)

%o SCRIPT

%o DIM i,0

%o DIM j,4

%o DIM k

%o DIM n,1

%o OPENFILEOUT myf,seq.txt

%o WRITE myf,i

%o WRITE myf,j

%o LABEL loop1

%o SET n,n+1

%o IF n>1000 THEN END

%o IF i%2==0 && j%2==0 THEN SET k,(i+j)/2

%o IF i%2==1 && j%2==1 THEN SET k,(i+j)/2

%o IF i%2==0 && j%2==1 THEN SET k,i/2+j

%o IF i%2==1 && j%2==0 THEN SET k,i+j/2

%o WRITE myf,k

%o SET i,j

%o SET j,k

%o GOTO loop1

%o (PARI) a(n, a=0, b=4)={n||return(a); for(i=2, n, b=if((b-a)%2, if(a%2, a+(a=b)\2, a\2+a=b), (a+a=b)\2)); b} \\ _M. F. Hasler_, Feb 10 2015

%Y Cf. A254330.

%K nonn

%O 1,1

%A _Pierre CAMI_, Jan 31 2015

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified September 24 03:45 EDT 2024. Contains 376185 sequences. (Running on oeis4.)