cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A343590 Undulating alternating primes.

This page as a plain text file.
%I A343590 #25 Jul 19 2021 09:23:07
%S A343590 2,3,5,7,23,29,41,43,47,61,67,83,89,101,103,107,109,163,181,307,383,
%T A343590 503,509,523,547,563,587,701,709,727,769,787,907,929,947,967,2141,
%U A343590 2143,2161,2309,2503,2549,2707,2729,2749,2767,2903,2909,2927,2969,4363,4507,4523,4547,4549,4703
%N A343590 Undulating alternating primes.
%C A343590 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).
%C A343590 The first 17 terms are the same as A030144; then a(18) = 163 while A030144(18) = 127.
%H A343590 Chai Wah Wu, <a href="/A343590/b343590.txt">Table of n, a(n) for n = 1..10000</a>
%e A343590 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.
%t A343590 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 *)
%o A343590 (Python)
%o A343590 from sympy import sieve
%o A343590 def sign(n): return (n > 0) - (n < 0)
%o A343590 def ok(p):
%o A343590   if p < 10: return True
%o A343590   s = str(p)
%o A343590   t = set(sign(int(s[i])%2-int(s[i-1])%2)*(-1)**i for i in range(1, len(s)))
%o A343590   t2 = set(sign(int(s[i])-int(s[i-1]))*(-1)**i for i in range(1, len(s)))
%o A343590   return (t == {1} or t == {-1}) and (t2 == {1} or t2 == {-1})
%o A343590 def aupto(limit): return [p for p in sieve.primerange(1, limit+1) if ok(p)]
%o A343590 print(aupto(4703)) # _Michael S. Branicky_, Apr 21 2021
%o A343590 (Python)
%o A343590 from sympy import isprime
%o A343590 def f(w,dir):
%o A343590     if dir == 1:
%o A343590         for s in w:
%o A343590             for t in range(int(s[-1])+1,10,2):
%o A343590                 yield s+str(t)
%o A343590     else:
%o A343590         for s in w:
%o A343590             for t in range(1-int(s[-1])%2,int(s[-1]),2):
%o A343590                 yield s+str(t)
%o A343590 A343590_list = []
%o A343590 for l in range(5):
%o A343590     for d in '123456789':
%o A343590         x = d
%o A343590         for i in range(1,l+1):
%o A343590             x = f(x,(-1)**i)
%o A343590         A343590_list.extend([int(p) for p in x if isprime(int(p))])
%o A343590         if l > 0:
%o A343590             y = d
%o A343590             for i in range(1,l+1):
%o A343590                 y = f(y,(-1)**(i+1))
%o A343590             A343590_list.extend([int(p) for p in y if isprime(int(p))]) # _Chai Wah Wu_, Apr 25 2021
%Y A343590 Intersection of A030144 and A059168.
%Y A343590 A343591 is a subsequence.
%K A343590 nonn,base
%O A343590 1,1
%A A343590 _Bernard Schott_, Apr 21 2021