login
Cardinality of the (ordered) list L_n defined inductively by: L_1 = {2}; L_(n+1) = L_n - {p}, where p is the first member of L_n, from left to right, such that prime(n+1) can be appended to the end or beginning of p so that the neighboring digits are equal, if p exists; append prime(n+1) to the end of L_n, otherwise.
2

%I #17 Mar 06 2020 15:49:00

%S 1,2,3,4,5,4,3,2,1,2,3,4,5,4,5,4,5,6,7,6,5,4,5,6,5,4,3,4,5,6,7,6,7,8,

%T 9,8,9,10,11,12,13,12,11,12,13,14,13,14,15,16,17,18,17,16,17,18,19,18,

%U 19,18,19,20,19,18,17,16,15,14,13,12,11,10,11,10

%N Cardinality of the (ordered) list L_n defined inductively by: L_1 = {2}; L_(n+1) = L_n - {p}, where p is the first member of L_n, from left to right, such that prime(n+1) can be appended to the end or beginning of p so that the neighboring digits are equal, if p exists; append prime(n+1) to the end of L_n, otherwise.

%C It appears that a(n) is growing slowly on the average. (A moving average filter applied to the sequence will show an upward trend.) Probably a(n) > 0 for all n, but lacking a proof, one is never sure. For example, L_9 = {5} comes perilously close to extinction. It would be interesting to have a closed-form expression giving, at least asymptotically, the value of a(n).

%H Eric M. Schmidt, <a href="/A062406/b062406.txt">Table of n, a(n) for n = 1..10000</a>

%e L_n for n = 1..5 are: {2}, {2,3}, {2,3,5}, {2,3,5,7}, {2,3,5,7,11}. The first five values of the sequence are then 1,2,3,4,5, respectively. For n = 6, Prime(6) = 13 can be appended to the beginning of 3 in L_5 so that the neighboring digits (i.e., 3's) are equal, so eliminate 3 from L_5 to get L_6 = {2,5,7,11}. Hence a(6) = 4.

%o (Sage)

%o def a_list(n) :

%o res = []

%o curlist = []

%o for m in range(1,n+1) :

%o d = nth_prime(m).digits()

%o ds = (d[-1], d[0])

%o remitem = next((i for i in range(len(curlist)) if curlist[i][0] == ds[1] or curlist[i][1] == ds[0]), None)

%o if remitem != None : del curlist[remitem]

%o else : curlist.append(ds)

%o res.append(len(curlist))

%o return res

%o # _Eric M. Schmidt_, Oct 19 2016

%Y Cf. A067854.

%K nonn,base

%O 1,2

%A _Joseph L. Pe_, Feb 13 2002

%E Extended and corrected and definition edited by _Eric M. Schmidt_, Oct 19 2016