%I #13 Mar 06 2020 12:02:30
%S 1,2,3,4,5,5,5,5,5,6,6,6,6,7,8,8,9,9,10,10,10,10,11,12,12,12,12,12,13,
%T 14,15,15,16,17,18,18,19,20,21,22,23,23,23,24,25,26,26,27,28,29,30,31,
%U 31,31,32,33,34,34,35,35,36,37,37,37,37,37,37,37,37,37
%N a(n) = cardinality of the (ordered) list L_n defined inductively by: L_1 = {2}; if, reading from left to right, there is a member p of L_n such that prime(n+1) can be appended to the beginning or end of p so that their neighboring digits are equal, then append prime(n+1) to the beginning or end of p to obtain L_(n+1); otherwise, add prime(n+1) to the end of the list L_n to obtain L_(n+1).
%H Eric M. Schmidt, <a href="/A067854/b067854.txt">Table of n, a(n) for n = 1..10000</a>
%e L_n for 1,...,5 are: {2}, {2,3}, {2,3,5}, {2,3,5,7}, {2,3,5,7,11}, so that a(i) = i for i = 1,...,5. Prime(6) = 13 can be appended to the beginning of 3 (in L_5) so that their neighboring digits (i.e. 3s) are equal. Hence L_6 = {2,133,5,7,11} and a(6) = 5. Prime(7) = 17 can be appended to the beginning of 7 in L_6 so that their neighboring digits are equal; so L_7 = {2,133,5,177,11} and a(7) = 5. It would be interesting to have a closed-form expression giving, at least asymptotically or statistically, the value of a(n).
%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 matcheditem = false
%o for i in range(len(curlist)) :
%o if curlist[i][0] == ds[1] :
%o curlist[i][0] = ds[0]
%o matcheditem = true
%o break
%o if curlist[i][1] == ds[0] :
%o curlist[i][1] = ds[1]
%o matcheditem = true
%o break
%o if not matcheditem : curlist.append(ds)
%o res.append(len(curlist))
%o return res
%o # _Eric M. Schmidt_, Oct 20 2016
%Y Cf. A062406.
%K base,easy,nonn
%O 1,2
%A _Joseph L. Pe_, Feb 15 2002
%E Extended and corrected by _Eric M. Schmidt_, Oct 20 2016