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.

A068876 Smallest n-digit prime with property that digits alternate in parity.

This page as a plain text file.
%I A068876 #26 Mar 08 2020 00:04:17
%S A068876 2,23,101,2129,10103,210101,1010129,21010127,101010167,2101010147,
%T A068876 10101010163,210101010187,1010101010341,21010101010147,
%U A068876 101010101010323,2101010101010141,10101010101010141,210101010101010323,1010101010101010143
%N A068876 Smallest n-digit prime with property that digits alternate in parity.
%H A068876 Robert Israel, <a href="/A068876/b068876.txt">Table of n, a(n) for n = 1..700</a>
%e A068876 a(4) = 2129 as 2, 1, 2 and 9 have even and odd parity alternately.
%p A068876 alp:= proc(n) local L,d;
%p A068876 L:= convert(n,base,10);
%p A068876 d:= nops(L);
%p A068876 if d::even then L:= L + map(op, [[0,1]$(d/2)]) else L:= L + map(op, [[0,1]$((d-1)/2),[0]]) fi;
%p A068876 nops(convert(L mod 2, set))=1
%p A068876 end proc:
%p A068876 f:= proc(d) local s;
%p A068876   if d::even then s:= 2*10^(d-1)+(10^d-1)/99-1
%p A068876   else s:= (10^(d+1)-1)/99-1
%p A068876   fi;
%p A068876   do s:= nextprime(s);
%p A068876      if alp(s) then return s fi
%p A068876   od
%p A068876 end proc:
%p A068876 seq(f(d),d=1..20); # _Robert Israel_, Aug 14 2018
%t A068876 fQ[n_] := Block[{m = Mod[ IntegerDigits@ n, 2]}, m == Split[m, UnsameQ][[1]]]; f[n_] := Block[{c = 1 + 100 (100^Ceiling[n/2 - 1] - 1)/99, k}, k = If[ OddQ@ n, c, 2*10^(n - 1) + c]; k = NextPrime[k - 1]; While[ !fQ@ k, k = NextPrime@ k]; k]; Array[f, 21] (* _Robert G. Wilson v_, Apr 01 2011 *)
%o A068876 (Sage)
%o A068876 concat = lambda x: Integer(''.join(map(str,x)),base=10)
%o A068876 def A068876(n):
%o A068876     dd = {0:range(0,10,2), 1: range(1,10,2)}
%o A068876     for d0 in [1..9]:
%o A068876         if n % 2 == 0 and d0 % 2 == 1: continue # optimization
%o A068876         ds = [dd[(d0+1+i) % 2] for i in range(n-1)]
%o A068876         for dr in cartesian_product(ds):
%o A068876             c = concat([d0]+dr)
%o A068876             if is_prime(c): return c  # _D. S. McNeil_, Apr 02 2011
%Y A068876 Cf. A030144, A068877, A056830.
%K A068876 nonn,base
%O A068876 1,1
%A A068876 _Amarnath Murthy_, Mar 19 2002
%E A068876 a(9)-a(13) corrected and a(14)-a(19) from _Donovan Johnson_, Apr 01 2011