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
4, 15, 52, 210, 1007, 5156, 25571, 133293, 727082, 3874464, 21072166, 117829671, 654556778 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,1
COMMENTS
'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.
REFERENCES
C. A. Pickover, "Wonders of Numbers", Oxford New York 2001, Chapter 52, pp. 123-124, 316-317.
LINKS
C. A. Pickover, "Wonders of Numbers, Adventures in Mathematics, Mind and Meaning," Zentralblatt review
Eric Weisstein's World of Mathematics, Undulating Number.
PROG
(Python)
from sympy import isprime
from itertools import product
def sign(n): return (n > 0) - (n < 0)
def unds(n):
s = str(n)
if len(s) == 1: return True
signs = set(sign(int(s[i-1]) - int(s[i])) for i in range(1, len(s), 2))
if len(signs) > 1: return False
if len(s) % 2 == 0: return signs == {1} or signs == {-1}
return sign(int(s[-1]) - int(s[-2])) in signs - {0}
def candidate_pals(n): # of length 2n + 1
if n == 0: yield from [2, 3, 5, 7]; return # one-digit primes
for rightbutend in product("0123456789", repeat=n-1):
rightbutend = "".join(rightbutend)
for end in "1379": # multi-digit primes must end in 1, 3, 7, or 9
left = end + rightbutend[::-1]
for mid in "0123456789": yield int(left + mid + rightbutend + end)
def a(n): return sum(1 for p in candidate_pals(n) if unds(p) and isprime(p))
print([a(n) for n in range(6)]) # Michael S. Branicky, Apr 15 2021
(Python)
from sympy import isprime
def f(w, dir):
if dir == 1:
for s in w:
for t in range(int(s[-1])+1, 10):
yield s+str(t)
else:
for s in w:
for t in range(0, int(s[-1])):
yield s+str(t)
def A057332(n):
c = 0
for d in '123456789':
x = d
for i in range(1, n+1):
x = f(x, (-1)**i)
c += sum(1 for p in x if isprime(int(p+p[-2::-1])))
if n > 0:
y = d
for i in range(1, n+1):
y = f(y, (-1)**(i+1))
c += sum(1 for p in y if isprime(int(p+p[-2::-1])))
return c # Chai Wah Wu, Apr 25 2021
CROSSREFS
Sequence in context: A027295 A371217 A208722 * A230623 A162978 A171309
KEYWORD
nonn,base,more
AUTHOR
Patrick De Geest, Sep 15 2000
EXTENSIONS
a(5) from Donovan Johnson, Aug 08 2010
a(6)-a(10) from Lars Blomberg, Nov 19 2013
a(11) from Chai Wah Wu, Apr 25 2021
a(12) from Chai Wah Wu, May 02 2021
STATUS
approved

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 07:11 EDT 2024. Contains 371905 sequences. (Running on oeis4.)