login
Lexicographically earliest sequence of distinct positive terms such that either the concatenation [a(n); n; a(n+1)] or the concatenation [a(n+1); n; a(n)] is a prime number.
1

%I #49 Aug 11 2024 14:19:56

%S 1,2,3,4,9,6,19,8,7,10,21,11,17,13,5,39,16,29,14,31,20,27,24,57,23,32,

%T 33,26,53,12,49,35,37,15,43,22,67,30,59,18,73,28,61,41,51,70,47,25,69,

%U 34,89,42,79,38,71,52,77,48,93,45,91,44,63,58,99,36,83,50,87,55

%N Lexicographically earliest sequence of distinct positive terms such that either the concatenation [a(n); n; a(n+1)] or the concatenation [a(n+1); n; a(n)] is a prime number.

%C The sequence is a rearrangement of the positive integers.

%H Michael S. Branicky, <a href="/A375015/b375015.txt">Table of n, a(n) for n = 1..10000</a>

%H Eric Angelini, <a href="https://cinquantesignes.blogspot.com/2024/07/rightmost-digit-and-even-digits-to-its.html">Rightmost digit, leftmost digit, variants</a>, Personal blog of the author.

%e The first 11 terms are 1,2,3,4,9,6,19,8,7,10,21. Successively inserting n between a(n) and a(n+1) produce:

%e 112, 223, 334, 449, 956, 6619, 1978, 887, 7910, 101021.

%e If such a concatenation is composite, the concatenation [a(n+1);n;a(n)] is prime by construction.

%e 112, for instance, is not prime but 211 is. The same for 334 (composite) and 433 (prime), or 956 (composite) and 659 (prime). 7910 is not prime, but (0)197 is prime. If both concatenations are prime, we keep the smallest term.

%o (Python)

%o from sympy import isprime

%o from itertools import count, islice

%o def c(s, t, u): return isprime(int(s+t+u)) or isprime(int(u+t+s))

%o def agen(): # generator of terms

%o an, aset, m = 1, set(), 2

%o for n in count(1):

%o yield an

%o aset.add(an)

%o s, t = str(an), str(n)

%o an = next(k for k in count(m) if k not in aset and c(s, t, str(k)))

%o while m in aset: aset.discard(m); m += 1

%o print(list(islice(agen(), 70)))

%Y Cf. A000040.

%K base,nonn

%O 1,2

%A _Eric Angelini_ and _Michael S. Branicky_, Aug 08 2024