login
A343590
Undulating alternating primes.
5
2, 3, 5, 7, 23, 29, 41, 43, 47, 61, 67, 83, 89, 101, 103, 107, 109, 163, 181, 307, 383, 503, 509, 523, 547, 563, 587, 701, 709, 727, 769, 787, 907, 929, 947, 967, 2141, 2143, 2161, 2309, 2503, 2549, 2707, 2729, 2749, 2767, 2903, 2909, 2927, 2969, 4363, 4507, 4523, 4547, 4549, 4703
OFFSET
1,1
COMMENTS
Equivalently, primes in which the value of the digits alternately rises or falls (undulating, A059168) and in which the parity of the digits changes in turns (alternating, A030144).
The first 17 terms are the same as A030144; then a(18) = 163 while A030144(18) = 127.
EXAMPLE
2143 is a term as it is prime, digits 2, 1, 4 and 3 have even and odd parity alternately, and also alternately fall and rise.
MATHEMATICA
q[n_] := PrimeQ[n] && AllTrue[Differences[Sign @ Differences[(d = IntegerDigits[n])]], # != 0 &] && AllTrue[Differences @ Mod[d, 2], # != 0 &]; Select[Range[5000], q] (* Amiram Eldar, Apr 21 2021 *)
PROG
(Python)
from sympy import sieve
def sign(n): return (n > 0) - (n < 0)
def ok(p):
if p < 10: return True
s = str(p)
t = set(sign(int(s[i])%2-int(s[i-1])%2)*(-1)**i for i in range(1, len(s)))
t2 = set(sign(int(s[i])-int(s[i-1]))*(-1)**i for i in range(1, len(s)))
return (t == {1} or t == {-1}) and (t2 == {1} or t2 == {-1})
def aupto(limit): return [p for p in sieve.primerange(1, limit+1) if ok(p)]
print(aupto(4703)) # Michael S. Branicky, Apr 21 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, 2):
yield s+str(t)
else:
for s in w:
for t in range(1-int(s[-1])%2, int(s[-1]), 2):
yield s+str(t)
A343590_list = []
for l in range(5):
for d in '123456789':
x = d
for i in range(1, l+1):
x = f(x, (-1)**i)
A343590_list.extend([int(p) for p in x if isprime(int(p))])
if l > 0:
y = d
for i in range(1, l+1):
y = f(y, (-1)**(i+1))
A343590_list.extend([int(p) for p in y if isprime(int(p))]) # Chai Wah Wu, Apr 25 2021
CROSSREFS
Intersection of A030144 and A059168.
A343591 is a subsequence.
Sequence in context: A091727 A240920 A030144 * A343591 A323578 A156756
KEYWORD
nonn,base
AUTHOR
Bernard Schott, Apr 21 2021
STATUS
approved