OFFSET
1,2
COMMENTS
a(1)=1, a(2)=2, a(3)=3; a(n) is least k such that no three terms of a(1), a(2), ..., a(n-1), k form an arithmetic progression, except for the first triple (1,2,3).
LINKS
David A. Corneth, Table of n, a(n) for n = 1..8193 (first 512 terms by Jean-François Alcover)
Eric Weisstein's World of Mathematics, Nonarithmetic Progression Sequence.
FORMULA
MATHEMATICA
a[n_] := a[n] = If[n < 4, n, For[k = a[n - 1] + 1, True, k++, sp = SequencePosition[Append[Array[a, n - 1], k], {x_, ___, y_, ___, z_} /; y - x == z - y, 2]; If[sp == {{1, 3}}, Return[k]]]];
Table[Print[n, " ", a[n]]; a[n], {n, 1, 512}]
(* Comparing with data from conjectured formula: *)
b[n_] := If[n < 4, n, 1 + 2^(Length[id = IntegerDigits[n - 2, 2]] - 1) + FromDigits[id, 3]];
Table[b[n], {n, 1, 512}] (* Jean-François Alcover, Jan 15 2019 *)
(* Second [much faster] program: *)
upto[m_] := Module[{n, v, i, j}, n = Max[m, 3]; v = Table[1, {n}]; For[i = 3, i <= n-1, i++, If[v[[i]] == 1, For[j = Max[1, 2i-n], j <= Min[2n-i, i-1], j++, If[v[[j]] == 1, v[[2i-j]] = 0]]]]; Position[v, 1] // Flatten]; upto[12000] (* Jean-François Alcover, Jan 16 2019, after David A. Corneth *)
PROG
(PARI) upto(n) = n=max(n, 3); v=vector(n, i, 1); for(i=3, n-1, if(v[i]==1, for(j = max(1, 2*i-n), min(2*n-i, i-1), c=2*i - j; if(v[j]==1, v[2*i-j]=0; )))); select(x -> x==1, v, 1) \\ David A. Corneth, Jan 15 2019
CROSSREFS
KEYWORD
nonn
AUTHOR
Ralf Stephan, Apr 04 2004
EXTENSIONS
Name clarified by Charles R Greathouse IV, Jan 30 2014
STATUS
approved