%I #38 Apr 26 2021 11:57:03
%S 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,
%T 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,
%U 21,15,0,10,0,9,0,4,23,0,5,44,0,6,17,44,0,7,50
%N 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.
%C 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.
%H Allan Teitelman, <a href="/A343554/b343554.txt">Table of n, a(n) for n = 1..10000</a>
%H Allan Teitelman, <a href="/A343554/a343554.c.txt">C Code</a>
%p b:= proc() [0$3] end:
%p a:= proc(n) option remember; local t; t:= (h->
%p `if`(h=0, 0, n-1-h))(`if`(n=1, 0, b(a(n-1))[1]));
%p b(t):= [b(t)[2..3][], n]; t
%p end:
%p seq(a(n), n=1..100); # _Alois P. Heinz_, Apr 19 2021
%t 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 *)
%o (C) see link above
%o (Python)
%o def aupton(terms):
%o n, alst, locs2 = 1, [0], dict()
%o while n < terms:
%o an = alst[-1]
%o if an in locs2:
%o if len(locs2[an]) > 1:
%o i = min(locs2[an]); locs2[an].discard(i); anp1 = n - i
%o else: anp1 = 0
%o else: locs2[an] = set(); anp1 = 0
%o alst.append(anp1); locs2[an].add(n); n += 1
%o return alst
%o print(aupton(82)) # _Michael S. Branicky_, Apr 24 2021
%Y Cf. A181391.
%K easy,nonn
%O 1,4
%A _Allan Teitelman_, Apr 19 2021
|