%I #33 Dec 23 2020 17:23:52
%S 1,2,4,1,9,2,1,21,2,3,1,8,2,23,18,2,8,7,9,2,1,20,16,1,21,36,3,32,2,3,
%T 4,11,13,8,2,13,27,4,18,3,7,5,8,133,3,22,31,46,19,8,47,14,3,2,14,10,
%U 44,3,5,1,10,3,9,6,19,73,39,22,36,6,1,60,17,32,227,2,134,9,45,11,33,3,37,1,8,12,14,8,1,67
%N Lexicographically earliest sequence of positive integers such that the sum of any number of consecutive terms can only repeat as sum of other consecutive terms after two or more terms between them.
%H S. Brunner, <a href="/A338789/b338789.txt">Table of n, a(n) for n = 1..10000</a>
%e The solution for a(5):
%e We look through the numbers step by step and if groups with the same sum are less than 2 terms apart they are put in brackets:
%e 1,2,4,[1],[1?] - not possible
%e [1,2],4,[1,2?] - not possible
%e 1,2,[4],[1,3?] - not possible
%e 1,2,[4],1,[4?] - not possible
%e 1,2,[4,1],[5?] - not possible
%e 1,[2,4],1,[6?] - not possible
%e 1,[2,4,1],[7?] - not possible
%e [1,2,4,1],[8?] - not possible
%e 1,2,4,1,9?
%e There are no 2 sums which contradict the definition of this sequence with a(5) = 9, so this is the next term. In this case we knew it must be the solution because the upper bound of a(n) is always the sum of all previous terms + 1.
%e Another example for a(8) = 21:
%e 1,2,4,1,9,2,[1],[1?] ; 1,2,4,1,9,[2],1,[2?] ; 1,2,4,1,9,[2,1],[3?]
%e 1,[2,4,1],9,[2,1,4?] ; [1,2,4,1],9,[2,1,5?] ; 1,2,4,1,[9],[2,1,6?]
%e 1,2,4,[1,9],[2,1,7?] ; 1,2,4,1,[9],2,[1,8?] ; 1,2,4,[1,9],2,[1,9?]
%e 1,2,4,1,[9,2],[1,10?] ; 1,2,4,1,[9,2],1,[11?] ; 1,2,4,1,[9,2,1],[12?]
%e 1,2,4,[1,9,2,1],[13?] ; [1,2,4,1,9],[2,1,14?] ; 1,2,[4,1,9,2],[1,15?]
%e 1,2,[4,1,9,2],1,[16?] ; 1,2,[4,1,9,2,1],[17?] ; 1,[2,4,1,9,2],1,[18?]
%e 1,[2,4,1,9,2,1],[19?] ; [1,2,4,1,9,2,1],[20?] ; 1,2,4,1,9,2,1,21?
%e -> a(8) = 21.
%o (Python)
%o def A(lastn):
%o n,a,chk,nchk=1,[],[],[]
%o while n<=lastn:
%o i=1
%o while i in chk: i+=1
%o for x, v in enumerate(chk): chk[x]=v-i
%o chk.extend(nchk)
%o for x, v in enumerate(nchk): nchk[x]=v+i
%o nchk.append(i)
%o chk.extend(nchk)
%o chk=[x for x in chk if x>0]
%o chk=list(set(chk))
%o a.append(i)
%o print(i)
%o n += 1
%o return a
%Y Cf. A002048.
%K nonn,look
%O 1,2
%A _S. Brunner_, Nov 09 2020