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”).

a(0) = 1; a(n) = |a(n-1) - n| if n is has already appeared in the sequence, otherwise a(n) = a(n-1) + n.
1

%I #11 Sep 03 2017 13:22:52

%S 1,0,2,5,9,4,10,17,25,16,6,17,29,42,56,71,55,38,56,75,95,116,138,161,

%T 185,160,186,213,241,212,242,273,305,338,372,407,443,480,442,481,521,

%U 562,520,563,607,652,698,745,793,842,892,943,995,1048,1102,1047,991

%N a(0) = 1; a(n) = |a(n-1) - n| if n is has already appeared in the sequence, otherwise a(n) = a(n-1) + n.

%p a[0]:=1: S:={1}: for n from 1 to 65 do if member(n,S)=true then a[n]:=abs(a[n-1]-n): S:=S union {a[n]} else a[n]:=a[n-1]+n: S:=S union {a[n]} fi od: seq(a[n],n=0..65); # _Emeric Deutsch_, May 07 2006

%t f[s_] := Block[{n,},n = Length[s]; Return[Append[s, Abs[Last[s] + If[MemberQ[s, n], -n, +n]]]];]; Nest[f, {1}, 66] (* _Ray Chandler_, May 06 2006 *)

%Y Cf. A005132, A118906.

%K easy,nonn

%O 0,3

%A _Leroy Quet_, May 05 2006

%E Extended by _Ray Chandler_ and _Emeric Deutsch_, May 06 2006