OFFSET
0,2
COMMENTS
When a location is visited more than once, each such visit counts in a(n).
EXAMPLE
For n=0 there are no locations 0..n-1, so the sole possible path is empty which is a(0) = 0 locations.
For n=1, the sole possible path is location 0 twice, 0 -> 0, which is 2 locations a(1) = 2.
For n=12, a path of a(12) = 8 locations visited starting from n-1 = 11 is:
11 -> 9 -> 11 -> 9 -> 7 -> 8 -> 10 -> 6
Locations 11 and 9 are visited twice each and the others once.
i = 0 1 2 3 4 5 6 7 8 9 10 11
a(i) = 0, 2, 1, 2, 4, 3, 8, 1, 2, 2, 4, 2
2<----2
---->2
1<----2<----
->2---->4
8<----------
PROG
(Python)
def A(lastn, times=2, 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