OFFSET
1,2
COMMENTS
More formally: from index i, move to index i - a(i), resp. to i + a(i), if a(i) is prime, resp. not prime.
The sequence is conjectured to be a permutation of the positive integers.
See A330154 for the lexicographic earliest variant, rather than choosing the largest possible prime (and choosing terms following the journey).
LINKS
Hugo Pfoertner, Table of n, a(n) for n = 1..10000 (first 1138 terms from Jean-Marc Falcoz)
EXAMPLE
At index i = 1, a(1) = 1 is the smallest available number and possible since it drives to the right. This implies a move of a(1) = 1 place to the right, i.e., to index i = 2.
Then a(2) cannot be 2 or a larger prime, since this would imply a move too far to the left, so we choose the smallest available composite number, a(2) = 4. This takes us 4 places further to the right, to index 2 + 4 = 6.
Then a(6) can be equal to the prime 3, but not 5 which would drive back to a(1) and create a loop, preventing from visiting all terms. This leads to index 6 - 3 = 3.
Then a(3) cannot be 2 which would lead to already visited a(1), nor a larger prime which would take too far to the left. So a(3) = 6, the smallest available composite number. This leads to index 3 + 6 = 9.
Here a(9) can be a prime, the largest possible choice is a(9) = 5, leading to index 9 - 5 = 4.
Now a(4) cannot be 2 nor 3 nor a larger prime. Therefore a(4) = 8, the smallest available composite number. This leads to index 4 + 8 = 12.
PROG
(PARI) upto(N)={ my(U=[1], V=[2], f(k)=(-1)^isprime(k)*k, add(V, t)=if(V[1]+1<t, setunion(V, [t]), V[1]=t; while(#V>1&&V[2]==V[1]+1, V=V[^1]); V), A=Vec(1, N), done=1, n=1, k, t); while(n<=N||N>=n=valuation(done+1, 2), until(!A[n]|| N < n+=f(A[n]), bittest(done, n)&&(n=oo)&&break; done+=1<<n); n>N&& next; k=n-V[1]; while(U[1]<k=precprime(k-1), setsearch(U, k)|| setsearch(V, t=n-k)|| break); U[1]<k|| forcomposite(k=U[1]+1, oo, setsearch(U, k)|| setsearch(V, t=n+k)|| t<=V[1]|| break); U=add(U, A[n]=abs(t-n)); V=add(V, n=t)); print("Terms > "V[1]" may be incorrect."); A} \\ Use upto(600)[1..90] to get the displayed DATA, for smaller N, terms from a(72) = 180 on may be incorrect. - M. F. Hasler, Dec 05 2019
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Eric Angelini and Jean-Marc Falcoz, Nov 30 2019
STATUS
approved