%I #29 Apr 20 2023 09:23:34
%S 0,1,7,8,10,11,17,18,30,31,37,38,40,41,47,48,90,91,97,98,100,101,107,
%T 108,120,121,127,128,130,131,137,138,270,271,277,278,280,281,287,288,
%U 300,301,307,308,310,311,317,318,360,361,367,368,370,371,377,378,390
%N Stanley sequence S(0,1,7).
%C Lexicographic first increasing sequence starting (0, 1, 7, ...) and such that no 3 terms are in arithmetic progression. - _M. F. Hasler_, Jan 18 2016
%H Chai Wah Wu, <a href="/A266727/b266727.txt">Table of n, a(n) for n = 0..8191</a>
%H R. A. Moy and D. Rolnick, <a href="http://arxiv.org/abs/1502.06013">Novel structures in Stanley sequences</a>, arXiv:1502.06013 [math.CO], 2015.
%H R. A. Moy and D. Rolnick, <a href="http://dx.doi.org/10.1016/j.disc.2015.10.017">Novel structures in Stanley sequences</a>, Discrete Math., 339 (2016), 689-698.
%H A. M. Odlyzko and R. P. Stanley, <a href="https://math.mit.edu/~rstan/papers/od.pdf">Some curious sequences constructed with the greedy algorithm</a>, 1978.
%e a(3) = 8 because no 3 terms among (0,1,7,8) are in AP. a(4) is not 9 because (7,8,9) would be an AP, which is excluded. a(4) = 10 works, a(5) = 11 also.
%e For a(6), 12 is forbidden because of (8,10,12), 13 because of (7,10,13), 14 because of (8,11,14), 15 because of (7,11,15), 16 because of (0,8,16), thus a(6) = 17 is the smallest possible choice. - _M. F. Hasler_, Jan 18 2016
%t s = {0, 1, 7};
%t next[] := For[k = Last[s]+1; AppendTo[s, 0];, True, k++, s[[-1]] = k; sp = SequencePosition[s, {___, a_, ___, b_, ___, c_, ___} /; b-a == c-b, 1]; If[sp == {}, Print[k]; Break[]]];
%t Do[next[], {60}];
%t s (* _Jean-François Alcover_, Oct 04 2018 *)
%o (Python)
%o A266727_list = [0,1,7]
%o for i in range(1000):
%o n, flag = A266727_list[-1]+1, False
%o while True:
%o for j in range(i+2,0,-1):
%o m = 2*A266727_list[j]-n
%o if m in A266727_list:
%o break
%o if m < A266727_list[0]:
%o flag = True
%o break
%o else:
%o A266727_list.append(n)
%o break
%o if flag:
%o A266727_list.append(n)
%o break
%o n += 1 # _Chai Wah Wu_, Jan 05 2016
%o (PARI) A266727(n,show=1,L=3,v=[0,1,7],D=v->v[2..-1]-v[1..-2])={while(#v<=n, show&&print1(v[#v]","); v=concat(v,v[#v]); while(v[#v]++, forvec(i=vector(L,j,[if(j<L,j,#v),#v]),#Set(D(vecextract(v,i)))>1||next(2),2);break)); if(type(show)=="t_VEC",v,v[n+1])} \\ 2nd (optional) arg: zero = silent, nonzero = verbose, vector (e.g. [] or [1]) = get the whole list [a(0..n)] as return value, else just a(n). - _M. F. Hasler_, Jan 18 2016
%Y Cf. A005836, A188053, A266728.
%K nonn
%O 0,3
%A _N. J. A. Sloane_, Jan 04 2016