login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A057332 a(n) is the number of (2n+1)-digit palindromic primes that undulate. 4

%I #34 Apr 03 2023 10:36:09

%S 4,15,52,210,1007,5156,25571,133293,727082,3874464,21072166,117829671,

%T 654556778

%N a(n) is the number of (2n+1)-digit palindromic primes that undulate.

%C 'Undulate' means that the alternate digits are consistently greater than or less than the digits adjacent to them (e.g., 906343609). Smoothly undulating palindromic primes (e.g., 323232323) are a subset and included in the count.

%D C. A. Pickover, "Wonders of Numbers", Oxford New York 2001, Chapter 52, pp. 123-124, 316-317.

%H C. K. Caldwell, <a href="https://t5k.org/curios/page.php?short=906343609">Prime Curios! 906343609</a> and <a href="https://t5k.org/curios/page.php?short=1007">Prime Curios! 1007</a>.

%H C. A. Pickover, "Wonders of Numbers, Adventures in Mathematics, Mind and Meaning," <a href="http://www.zentralblatt-math.org/zmath/en/search/?q=an:0983.00008&amp;format=complete">Zentralblatt review</a>

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/UndulatingNumber.html">Undulating Number.</a>

%o (Python)

%o from sympy import isprime

%o from itertools import product

%o def sign(n): return (n > 0) - (n < 0)

%o def unds(n):

%o s = str(n)

%o if len(s) == 1: return True

%o signs = set(sign(int(s[i-1]) - int(s[i])) for i in range(1, len(s), 2))

%o if len(signs) > 1: return False

%o if len(s) % 2 == 0: return signs == {1} or signs == {-1}

%o return sign(int(s[-1]) - int(s[-2])) in signs - {0}

%o def candidate_pals(n): # of length 2n + 1

%o if n == 0: yield from [2, 3, 5, 7]; return # one-digit primes

%o for rightbutend in product("0123456789", repeat=n-1):

%o rightbutend = "".join(rightbutend)

%o for end in "1379": # multi-digit primes must end in 1, 3, 7, or 9

%o left = end + rightbutend[::-1]

%o for mid in "0123456789": yield int(left + mid + rightbutend + end)

%o def a(n): return sum(1 for p in candidate_pals(n) if unds(p) and isprime(p))

%o print([a(n) for n in range(6)]) # _Michael S. Branicky_, Apr 15 2021

%o (Python)

%o from sympy import isprime

%o def f(w,dir):

%o if dir == 1:

%o for s in w:

%o for t in range(int(s[-1])+1,10):

%o yield s+str(t)

%o else:

%o for s in w:

%o for t in range(0,int(s[-1])):

%o yield s+str(t)

%o def A057332(n):

%o c = 0

%o for d in '123456789':

%o x = d

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

%o x = f(x,(-1)**i)

%o c += sum(1 for p in x if isprime(int(p+p[-2::-1])))

%o if n > 0:

%o y = d

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

%o y = f(y,(-1)**(i+1))

%o c += sum(1 for p in y if isprime(int(p+p[-2::-1])))

%o return c # _Chai Wah Wu_, Apr 25 2021

%Y Cf. A046075, A033619, A032758, A039944, A016073, A046076, A046077, A057333.

%K nonn,base,more

%O 0,1

%A _Patrick De Geest_, Sep 15 2000

%E a(5) from _Donovan Johnson_, Aug 08 2010

%E a(6)-a(10) from _Lars Blomberg_, Nov 19 2013

%E a(11) from _Chai Wah Wu_, Apr 25 2021

%E a(12) from _Chai Wah Wu_, May 02 2021

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 23 10:29 EDT 2024. Contains 371905 sequences. (Running on oeis4.)