OFFSET
0,4
COMMENTS
In other words, if the last term has not appeared previously, take the absolute difference between the previous term and itself to obtain the next one; otherwise, add to the last term the difference between its index and that of the last identical term to obtain the next one.
The sequence is infinite, because loops are impossible.
LINKS
Sean A. Irvine, Java program (github)
EXAMPLE
a(0)=0 (given).
a(1)=1 (given).
a(2)=1: a(1) is not a term of a(0..0), therefore a(2) = |a(1) - a(0)| = 1 - 0 = 1.
a(3)=2: a(2)=a(1), therefore a(3) = a(2) + 2 - 1 = 1 + 2 - 1 = 2.
a(4)=1: a(3) is not a term of a(0..2), therefore a(4) = |a(3) - a(2)| = 2 - 1 = 1.
a(5)=3: a(4)=a(2), therefore a(5) = a(4) + 4 - 2 = 1 + 4 - 2 = 3.
a(6)=2: a(5) is not a term of a(0..4), therefore a(6) = |a(5) - a(4)| = 3 - 1 = 2.
MATHEMATICA
Nest[Function[{a, n}, Append[a, If[FreeQ[Most@ a, Last@ a], Abs[Subtract @@ a[[-2 ;; -1]] ], Last[a] + n - Position[Most@ a, _?(# == Last@ a &)][[-1, 1]] ]]] @@ {#, Length@ #} &, {0, 1}, 72] (* Michael De Vlieger, Jul 08 2019 *)
CROSSREFS
KEYWORD
nonn
AUTHOR
Marc Morgenegg, Jul 04 2019
STATUS
approved
