login
Recamán variation: a(1) = 1; for n > 1, a(n) = a(n-1)-prime(n) if that number is positive and not already in the sequence, otherwise a(n) = a(n-1)+prime(n).
0

%I #9 Apr 04 2014 01:49:14

%S 1,4,9,2,13,26,43,24,47,18,49,12,53,10,57,110,51,112,45,116,189,268,

%T 185,96,193,92,195,88,197,84,211,80,217,78,227,76,233,70,237,64,243,

%U 62,253,60,257,58,269,46,273,44,277,38,279,28,285,22,291,20,297,16,299,6,313

%N Recamán variation: a(1) = 1; for n > 1, a(n) = a(n-1)-prime(n) if that number is positive and not already in the sequence, otherwise a(n) = a(n-1)+prime(n).

%o (PARI) an=vector(100); an[1]=1; a(n)=if(n<0,0,an[n]); an[n]=if(abs(sign(a(n-1)-prime(n))-1)+setsearch(Set(vector(n-1,i,a(i))),a(n-1)-prime(n)),a(n-1)+prime(n),a(n-1)-prime(n))

%Y Cf. A005132.

%K nonn

%O 1,2

%A _Benoit Cloitre_, Feb 02 2003