%I #23 Apr 09 2024 16:38:38
%S 2,5,11,101,151,181,619,659,6229,10501,12821,15551,16091,18181,19861,
%T 60209,60509,61519,61819,62129,116911,119611,160091,169691,191161,
%U 196961,605509,620029,625529,626929,650059,655559,656959,682289,686989,688889
%N Strobogrammatic primes: the same upside down (calculator-style numerals).
%C This is the subsequence of primes in A018846. - _M. F. Hasler_, May 05 2012
%H Chai Wah Wu, <a href="/A018847/b018847.txt">Table of n, a(n) for n = 1..10000</a> (terms 1..648 from M. F. Hasler)
%t lst = {}; fQ[n_] := Block[{allset = {0, 1, 2, 5, 6, 8, 9}, id = IntegerDigits@n}, Union@ Join[id, allset] == allset && Reverse[id /. {6 -> 9, 9 -> 6}] == id]; Do[ If[ PrimeQ@n && fQ@n, AppendTo[lst, n]], {n, 700000}]; lst (* _Robert G. Wilson v_, Feb 27 2007 *)
%o (PARI) {write("/tmp/b018847.txt","1 2\n2 5"); c=2; s2=[0,1,2,5,6,8,9]; s=[0,1,2,5,8]; s1=[0,1,2,5,9,8,6]; for(n=2,9, p1=vector( (n+1)\2, i, 10^(i-1)); p2=vector( (n+1)\2, i, 10^(n-i)); forvec( v=vector((n+1)\2,i,if( i>1, [ 1,if( i>n\2, #s, #s1)], [2,5])), v[1]==3 & v[1]=5; ispseudoprime( t=sum(i=1,n\2,p1[i]*s1[v[i]]+p2[i]*s2[v[i]] ) +if(n%2,p1[#p1]*s[v[#v]] )) & /* print1(t",") */ write("/tmp/b018847.txt",c++" "t)))} \\ - _M. F. Hasler_, Apr 26 2012
%o (PARI) is_A018847(n,t=Vec("012..59.86"))={ isprime(n) & apply(x->t[eval(x)+1], n=Vec(Str(n)))==vecextract(n, "-1..1") } \\ - _M. F. Hasler_, May 05 2012
%o (Python)
%o from itertools import count, islice
%o from sympy import isprime
%o def A018847_gen(): # generator of terms
%o r, t, u = ''.maketrans('69','96'), set('0125689'), {0,1,2,5,8}
%o for x in count(1):
%o for y in range(10**(x-1),10**x):
%o if y%10 in u:
%o s = str(y)
%o if set(s) <= t and isprime(m:=int(s+s[-2::-1].translate(r))):
%o yield m
%o for y in range(10**(x-1),10**x):
%o s = str(y)
%o if set(s) <= t and isprime(m:=int(s+s[::-1].translate(r))):
%o yield m
%o A018847_list = list(islice(A018847_gen(),20)) # _Chai Wah Wu_, Apr 09 2024
%Y Cf. A007597 (more restrictive version not allowing digits 2 or 5).
%K nonn,base
%O 1,1
%A _David W. Wilson_