OFFSET
1,2
COMMENTS
When a location is visited more than once, each such visit counts in a(n).
a(0)=0 is no terms before n=0 so an empty path.
EXAMPLE
For n=6, the following is the longest chain of jumps starting from i = n-1 = 5,
1 2 3 4 5 location number i
0, 3, 1, 2, 2 a(i)
1<----
->2
3<----
------->2
1<----
->2
3<----
------->2
1<----
->2
3<----
It visited the terms 2,1,2,3 three times in a loop, which gives a total of 12 terms, so a(6)=12.
PROG
(Python)
def A(lastn, times=3, 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+1, a[n])
if mode>0:
u, q=0, []
while u<len(o):
q.append(a[o[u]])
u+=1
print(n+1, a[n], q, o)
return a
CROSSREFS
KEYWORD
nonn
AUTHOR
S. Brunner, Feb 14 2023
STATUS
approved