Question: How to compute a self referencing integer sequence

Requesting a code to compute the following self referencing integer sequence :

a(1)=1, a(2)=0. Thereafter, if a(n) is a novel term then a(n+1)=Min{|a(n)-a(k)|; 1<=k<n}. Otherwise, if a(n) seen before (most recently at a(m)), then a(n+1)=n-m.

First few terms are:


Desirable to have option for graphing results up to some value of n.

Thanks in advance for any assistance



Please Wait...