%I #43 Mar 18 2024 03:02:45
%S 0,0,1,1,1,2,1,3,2,1,4,3,1,5,3,2,2,3,3,4,1,6,4,2,4,3,5,1,7,1,8,4,4,5,
%T 2,5,3,6,1,9,1,10,6,2,6,3,7,1,11,5,4,6,4,7,2,7,3,8,1,12,11,1,13,8,2,8,
%U 3,9,1,14,7,4
%N If a(n) is not a term of a(0..n-1), then a(n+1) = a(n) - a(n - a(n)); otherwise a(n+1) is the number of terms equal to a(n) in a(0..n-1). Start with a(0)=0, a(1)=0.
%C In other words, if the last term a(n) has not appeared previously, subtract the term a(n - a(n)) from a(n) to get the next term. Otherwise, count the terms equal to the last term a(n) in a(0..n-1) to get the next term.
%C This sequence has no repeating pattern because of the rule a(n+1) = a(n) - a(n - a(n)).
%C A new record in the sequence is always the previous record + 1. Therefore all terms are >= 0.
%H Robert Israel, <a href="/A309596/b309596.txt">Table of n, a(n) for n = 0..10000</a>
%e a(0)=0 (given).
%e a(1)=0 (given).
%e a(2)=1: a(1)=0 is a term of a(0..0), therefore a(2) = Number of terms=0 in a(0..0) = 1.
%e a(3)=1: a(2)=1 is not a term of a(0..1), therefore: a(3) = a(2) - a(2 - 1) = 1 - 0 = 1.
%e a(4)=1: a(3)=1 is a term of a(0..2), therefore a(4) = Number of terms=1 in a(0..2) = 1.
%e a(5)=2: a(4)=1 is a term of a(0..3), therefore a(5) = Number of terms=1 in a(0..3) = 2.
%e a(6)=1: a(5)=2 is not a term of a(0..4), therefore: a(6) = a(5) - a(5 - 2) = 2 - 1 = 1.
%p R:= [0,0]:
%p for n from 2 to 100 do
%p q:= numboccur(R[-1],R[1..-2]);
%p if q = 0 then R:= [op(R),R[-1]-R[-1-R[-1]]] else R:= [op(R),q] fi
%p od:
%p R; # _Robert Israel_, Mar 17 2024
%t s={0,0}; Do[s1 = If[(c = Count[s[[1;;-2]], s[[-1]]]) == 0, s[[-1]] - s[[-1 - s[[-1]]]], c]; AppendTo[s, s1], {100}]; s (* _Amiram Eldar_, Aug 13 2019 *)
%o (Python)
%o sa, n = [0], 0
%o print(n,sa[n])
%o while n < 50:
%o i, j = 0, 0
%o while i < n:
%o if sa[i] == sa[n]:
%o j = j+1
%o i = i+1
%o if j == 0:
%o a = sa[n] - sa[n-sa[n]]
%o else:
%o a = j
%o n = n+1
%o print(n,a)
%o sa = sa+[a] # _A.H.M. Smeets_, Aug 09 2019
%Y Cf. A181391, A309035.
%K nonn,look
%O 0,6
%A _Marc Morgenegg_, Aug 09 2019
|