%I #11 Sep 03 2017 13:22:46
%S 1,2,4,1,5,10,4,3,5,4,14,3,9,4,18,3,13,4,22,3,17,4,26,3,21,4,30,3,25,
%T 4,34,3,29,4,38,3,33,4,42,3,37,4,46,3,41,4,50,3,45,4,54,3,49,4,58,3,
%U 53,4,62,3,57,4,66,3,61,4,70,3,65,4,74,3,69,4,78,3,73,4,82,3,77,4,86,3,81,4
%N a(0) = 1; a(n) = |a(n-1) - n| if n is not one of the earlier terms of the sequence, otherwise a(n) = a(n-1) + n.
%p a[0]:=1: S:={1}: for n from 1 to 100 do if member(n,S)=false 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..100); # _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}, 100] (* _Ray Chandler_, May 06 2006 *)
%Y Cf. A005132, A118907.
%K easy,nonn
%O 0,2
%A _Leroy Quet_, May 05 2006
%E Extended by _Ray Chandler_ and _Emeric Deutsch_, May 06 2006