%I #30 Apr 08 2022 12:39:17
%S 2,11,211,2111,12211,111121,1111211,11221211,111112121,1111111121,
%T 11111121121,111111211111,1111111121221,11111111112221,
%U 111111112111121,1111111112122111,11111111111112121,111111111111112111,1111111111111111111,11111111111111212121
%N Smallest n-digit prime containing only digits 1 or 2 or -1 if no such prime exists.
%C It is conjectured that such a prime always exists.
%C a(2), a(19), a(23), etc. are the prime repunits (A004023). a(1000) = (10^n-1)/9 + 111011000010.
%H Chai Wah Wu, <a href="/A036229/b036229.txt">Table of n, a(n) for n = 1..1000</a> (terms n=1..400 from Alois P. Heinz)
%H Robert G. Wilson v, <a href="/A036229/a036229.txt">Comments and first 100 terms</a>
%t Do[p = (10^n - 1)/9; k = 0; While[ ! PrimeQ[p], k++; p = FromDigits[ PadLeft[ IntegerDigits[ k, 2], n] + 1]]; Print[p], {n, 1, 20}]
%t Table[Min[Select[ FromDigits/@Tuples[{1,2},n],PrimeQ]],{n,20}] (* _Harvey P. Dale_, Feb 05 2014 *)
%o (Python)
%o from sympy import isprime
%o def A036229(n):
%o k, r, m = (10**n-1)//9, 2**n-1, 0
%o while m <= r:
%o t = k+int(bin(m)[2:])
%o if isprime(t):
%o return t
%o m += 1
%o return -1 # _Chai Wah Wu_, Aug 18 2021
%Y Cf. A036937, A068086.
%K nonn,base,nice
%O 1,1
%A _G. L. Honaker, Jr._
%E Edited by _N. J. A. Sloane_ and _Robert G. Wilson v_, May 03 2002
%E Escape clause added by _Chai Wah Wu_, Aug 18 2021