login
A360593
Each term a(i) can reach a(i+a(i)) and a(i-a(i)) if these terms exist. a(n) is the greatest number of terms among a(1..n-1) that can be reached by starting at a(n-1) and visiting no term more than once; a(0)=0. See example.
10
0, 1, 2, 2, 4, 2, 6, 2, 7, 5, 6, 6, 9, 10, 10, 6, 8, 7, 9, 8, 11, 8, 12, 14, 12, 14, 19, 16, 19, 14, 14, 16, 14, 21, 14, 16, 21, 14, 14, 16, 14, 18, 14, 16, 21, 21, 19, 21, 22, 22, 21, 23, 24, 24, 29, 29, 22, 26, 24, 28, 24, 26, 31, 24, 31, 34, 24, 30, 34, 29, 39
OFFSET
0,3
COMMENTS
For clarification:
The terms of the sequence so far are written as a one-dimensional grid, and from every term a(i) you can jump back or forth a(i) terms, without i getting < 0 or > n, as these terms don't exist. Then search for the longest possible chain of jumps you can do starting at a(n) and visiting no term more than once. The number of targets visited by this chain is the next term of the sequence.
A chain of jumps C always starts at n, with C1 = a(n-1). Then the first jump always has to go back C1 terms, so C2 = a(n-1-C1) = a(n-1-a(n-1)), and then it continues with jumping back or forth C2 terms, whichever produces the longest chain of jumps:
C3 = a(n-1-C1-C2) or a(n-1-C1+C2),
C4 = a(n-1-C1{-/+}C2{-/+}C3), etc.
The first numbers which appear to be missing from this sequence are:
3, 13, 15, 17, 20, 25, 27, 32, 33, 36, 43, 44, 48, 50, 51, 62, 63, 69, 70, 71, 75, 77, 78, 80, etc.
EXAMPLE
This example shows the longest chain of jumps starting with a(7)=2:
0, 1, 2, 2, 4, 2, 6, 2
1<----2<----2<----2
->2---->4
0<----------
It visited the 7 terms 2,2,2,1,2,4,0. So a(8)=7.
PROG
(Python)
def A(lastn, times=1, mode=0):
a, n=[0], 0
while n<lastn:
d, i, v, o, g, r=[[n]], 0, 1, [], 0, 0
while len(d)>0:
if len(d[-1])>v: v, o=len(d[-1]), d[-1][:]
if d[-1][-1]-a[d[-1][-1]]>=0:
if d[-1].count(d[-1][-1]-a[d[-1][-1]])<times:g=1
if d[-1][-1]+a[d[-1][-1]]<=n:
if d[-1].count(d[-1][-1]+a[d[-1][-1]])<times:
if g>0: d.append(d[-1][:])
d[-1].append(d[-1][-1]+a[d[-1][-1]])
r=1
if g>0:
if r>0: d[-2].append(d[-2][-1]-a[d[-2][-1]])
else: d[-1].append(d[-1][-1]-a[d[-1][-1]])
r=1
if r==0:d.pop()
r, g=0, 0
a.append(v)
n+=1
if mode==0: print(n, a[n])
if mode>0:
u, q=0, []
while u<len(o):
q.append(a[o[u]])
u+=1
print(n, a[n], q, o)
return a
CROSSREFS
KEYWORD
nonn
AUTHOR
S. Brunner, Feb 13 2023
STATUS
approved