|
|
A343554
|
|
a(1) = 0. For n >= 1, if there exists i < j < n such that a(i) = a(j) = a(n), take the largest such i and set a(n+1) = n-i; otherwise a(n+1) = 0.
|
|
1
|
|
|
0, 0, 0, 2, 0, 3, 0, 4, 0, 4, 0, 4, 4, 3, 0, 6, 0, 6, 0, 4, 8, 0, 5, 0, 5, 0, 4, 14, 0, 5, 7, 0, 6, 17, 0, 6, 18, 0, 6, 6, 4, 21, 0, 8, 0, 7, 0, 4, 21, 0, 5, 26, 0, 6, 15, 0, 6, 17, 0, 6, 6, 4, 21, 21, 15, 0, 10, 0, 9, 0, 4, 23, 0, 5, 44, 0, 6, 17, 44, 0, 7, 50
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,4
|
|
COMMENTS
|
A variant of "Van Eck's" sequence A181391, but "looking back" for the second to last appearance of the value of a(n) instead of the last one. If a(n) has appeared just once before, a(n+1) is also 0.
|
|
LINKS
|
|
|
MAPLE
|
b:= proc() [0$3] end:
a:= proc(n) option remember; local t; t:= (h->
`if`(h=0, 0, n-1-h))(`if`(n=1, 0, b(a(n-1))[1]));
b(t):= [b(t)[2..3][], n]; t
end:
|
|
MATHEMATICA
|
a[1]=0; a[n_]:=a[n]=If[Length[s=Position[Array[a, n-1], a[n-1]]]>2, First@@{s[[-1]]-s[[-3]]}, 0]; Array[a, 100] (* Giorgos Kalogeropoulos, Apr 24 2021 *)
|
|
PROG
|
(C) see link above
(Python)
def aupton(terms):
n, alst, locs2 = 1, [0], dict()
while n < terms:
an = alst[-1]
if an in locs2:
if len(locs2[an]) > 1:
i = min(locs2[an]); locs2[an].discard(i); anp1 = n - i
else: anp1 = 0
else: locs2[an] = set(); anp1 = 0
alst.append(anp1); locs2[an].add(n); n += 1
return alst
|
|
CROSSREFS
|
|
|
KEYWORD
|
easy,nonn
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|