OFFSET
1,2
COMMENTS
This sequence is a permutation of the positive integers. A number cannot remain unassigned indefinitely; eventually the placement gets far enough from its neighbors and it gets used.
Each term in this sequence is either the next unused even number or the next unused odd number; after the initial 5 terms there are always 2 or 3 odd numbers between each pair of even numbers.
EXAMPLE
After a(1) = 1, we cannot have a(2) = 2, because then 1 and 2 would be too close. a(2) = 3 is OK. Now a(3) can't be 2 because then 2 and 3 would be too close; 4 would also be too close to 3, but 5 is OK. Skipping ahead, a(6) is the first place where 2 is not too close to 3, so a(6) = 2.
PROG
(PARI) dist(n) = n+1
al(n)= {local(v, w, mn, ok);
v=vector(n); w=vector(2*n); u=vector(n);
v[1]=w[1]=1; mn=2;
for(k=2, n,
j=mn-1; ok=0;
while(!ok,
j++; ok=w[j]==0;
if(ok&w[j-1]&abs(k-w[j-1])<dist(j), ok=0);
if(ok&w[j+1]&abs(k-w[j+1])<dist(j+1), ok=0));
v[k]=j; w[j]=k);
while(w[mn], mn++);
v}
CROSSREFS
KEYWORD
nonn
AUTHOR
Franklin T. Adams-Watters, Oct 27 2009
STATUS
approved
