login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
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
Allan Teitelman, C Code
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:
seq(a(n), n=1..100); # Alois P. Heinz, Apr 19 2021
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
print(aupton(82)) # Michael S. Branicky, Apr 24 2021
CROSSREFS
Cf. A181391.
Sequence in context: A338569 A343757 A108760 * A137304 A234581 A234582
KEYWORD
easy,nonn
AUTHOR
Allan Teitelman, Apr 19 2021
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified June 8 18:04 EDT 2023. Contains 363165 sequences. (Running on oeis4.)