OFFSET
1,2
EXAMPLE
For n=5, S={1,3,7,12, 2,4,5} so d=6. a(4)-d=6 is in S union {6}, so we have a(5)=a(4)+d=18.
a(28) does not exist: d=43, but both a(28)-43=11 and a(28)+43=97 are in S union {43}.
MATHEMATICA
mex1[s_]:=Module[{n}, For[n=1, MemberQ[s, n], n++, Null]; n]; a[1]=1; a[n_]:=a[n]=Module[{as, d}, as=a/@Range[n-1]; as=Union[as, Abs[Drop[as, 1]-Drop[as, -1]]]; AppendTo[as, d=mex1[as]]; If[a[n-1]-d>0&&!MemberQ[as, a[n-1]-d], a[n-1]-d, If[ !MemberQ[as, a[n-1]+d], a[n-1]+d], False]]
CROSSREFS
KEYWORD
nonn,fini,full
AUTHOR
Dean Hickerson, following a suggestion of Leroy Quet, May 28 2004
STATUS
approved