%I #26 Mar 31 2023 02:59:25
%S 0,2,4,1,3,5,7,9,6,8,10,12,14,11,13,15,17,19,16,18,20,22,24,21,23,25,
%T 27,29,26,28,30,32,34,31,33,35,37,39,36,38,40,42,44,41,43,45,47,49,46,
%U 48,50,52,54,51,53,55,57,59,56,58,60,62,64,61,63,65,67,69,66,68,70,72,74,71,73,75,77,79,76,78,80,82,84,81,83,85,87,89,86,88,90
%N Lexicographically earliest nonnegative sequence such that |a(n+1)-a(n)| is a prime number, and no number occurs twice; a(0) = 0.
%C A variant of A277616, which is defined in a similar way with squares > 1 instead of primes.
%C The steps a(n+1)-a(n) are either +2 or -3, after 10 terms we get a(n+10), and the first 10 terms are all numbers between 0 and 9: This sequence is obviously a permutation of the nonnegative integers, with a(n) = a(n-5) + 5 for all n > 5. The strictly positive variant (starting with a(1) = 1) is given by A065186.
%H <a href="/index/Rec#order_06">Index entries for linear recurrences with constant coefficients</a>, signature (1,0,0,0,1,-1).
%F a(n) = a(n-5) + 5 for all n > 5.
%F a(n) = A065186(n+1) - 1.
%F G.f.: x*(2*x^4 + 2*x^3 - 3*x^2 + 2*x + 2)/(x^6 - x^5 - x + 1). - _Chai Wah Wu_, Mar 30 2023
%t Table[n - 2 + Mod[n - 3, 5], {n, 0, 500}] (* _Fred Patrick Doty_, Aug 03 2020 *)
%o (PARI) {u=[a=0];(chk(n)=(!#u||(n>u[1]&&!setsearch(u,n)))&&(u=setunion(u,[n]))&&!while(#u>1&&u[2]==u[1]+1,u=u[^1]));for(n=1,99,print1(a","); for(k=-primepi(a+!a-1),9e9, k||next; chk(a+sign(k)*prime(abs(k)))||next; a+=sign(k)*prime(abs(k));break))}
%o (PARI) A277618(n,i=[0,2,4,1,3])=i[n%#i+1]+n\#i*#i
%Y Cf. A277616, A277617, A065186.
%K nonn,easy
%O 0,2
%A _Eric Angelini_ and _M. F. Hasler_, Oct 23 2016
%E Offset corrected by _R. J. Mathar_, Jun 19 2021