login
Start with a(1)=1, if a(n) is prime, jump over a(n) neighbors to the left, else to the right. Fill in the largest possible unused prime, or the least unused composite, such that the next destination is not yet filled.
2

%I #17 Dec 23 2024 14:53:42

%S 1,6,4,10,8,9,14,5,3,26,18,12,22,7,2,11,27,16,34,28,50,15,24,35,17,39,

%T 51,57,38,20,45,32,44,87,23,21,13,19,94,48,69,72,62,93,30,63,65,25,31,

%U 58,37,80,54,29,102,96,82,47,77,36,90,114,153,138,33,40,117,41,106,68,134

%N Start with a(1)=1, if a(n) is prime, jump over a(n) neighbors to the left, else to the right. Fill in the largest possible unused prime, or the least unused composite, such that the next destination is not yet filled.

%C "Largest possible" means that the prime has to be less than n-1 (to be able to jump over a(n) neighbors to the left) and the place at index n-a(n)-1 has to be vacant. If (and only if) no such prime exists, the "or" clause (filling with composite) applies.

%H M. F. Hasler, <a href="/A182164/b182164.txt">Table of n, a(n) for n = 1..313</a>

%H E. Angelini, <a href="https://web.archive.org/web/*/http://list.seqfan.eu/oldermail/seqfan/2012-April/009397.html">Jumping back and forth (primes and composites)</a>, SeqFan list, Apr 15 2012

%o (PARI) A182164_list(N_min,debug)= my(L=1 /* least unfilled position */, p=1 /* current position */, u=0 /* used numbers (bitmap) */, a=vector(7*N_min)); a[1]=1; while( while (a[L] ,L++) || L<N_min, p += (a[p]+1) * (-1)^isprime(a[p]); forstep( t=p-L, 2, -1, t=precprime(t); !bittest(u,t) && !a[p-t-1] && (u+=1<<a[p]= t) && next(2)); for (t=4,9e9, bittest(u,t) && next; isprime(t) && next; #a>p+t || a=concat(a,vector(p+t+1-#a)); a[p+t+1] && next; u+=1<<a[p]=t; break)); debug && print("Largest used: ",#a); vecextract(a,2^(L-1)-1)

%K nonn

%O 1,2

%A _Eric Angelini_ and _M. F. Hasler_, Apr 15 2012