OFFSET
1,1
COMMENTS
If we start with a(1)=a(2)=2, then a(n)=2 for every n.
As N increases, sum_{n=1..N} 1/a(n) converges quickly to
2.6332482094949767034995557279162460374965915768...
More generally, if one starts with a(1) = a(2), then a(n) = a(1) for every n.
LINKS
Pierre CAMI, Table of n, a(n) for n = 1..1000
EXAMPLE
As 2 is even and 3 is odd, a(4) = 2/2 + 3 = 4.
As 3 is odd and 4 is even, a(5) = 3 + 4/2 = 5.
MATHEMATICA
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 *)
PROG
(PFGW & SCRIPT)
SCRIPT
DIM i, 0
DIM j, 4
DIM k
DIM n, 1
OPENFILEOUT myf, seq.txt
WRITE myf, i
WRITE myf, j
LABEL loop1
SET n, n+1
IF n>1000 THEN END
IF i%2==0 && j%2==0 THEN SET k, (i+j)/2
IF i%2==1 && j%2==1 THEN SET k, (i+j)/2
IF i%2==0 && j%2==1 THEN SET k, i/2+j
IF i%2==1 && j%2==0 THEN SET k, i+j/2
WRITE myf, k
SET i, j
SET j, k
GOTO loop1
(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
CROSSREFS
KEYWORD
nonn
AUTHOR
Pierre CAMI, Jan 31 2015
STATUS
approved