7 deleted 19 characters in body
source | link

Java (OpenJDK 8), 164164 110 bytes

  
int f(int a)->{if(a<1)return 2;int i=(int)Math.pow(10,a-1);for i=0;for(;!(i+"").substring(0,a).matches("2+""2{"+a+"}.*")||new|new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

That second regex there matches composite unary integers.Thanks to @FryAmTheEggman for a bunch of bytes!

Try it online!Try it online!

Java (OpenJDK), 164 bytes

 
int f(int a){if(a<1)return 2;int i=(int)Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")||new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

That second regex there matches composite unary integers.

Try it online!

Java (OpenJDK 8), 164 110 bytes

 
a->{int i=0;for(;!(i+"").matches("2{"+a+"}.*")|new String(new char[i]).matches(".?|(..+)\\1+");i++);return i;}

Thanks to @FryAmTheEggman for a bunch of bytes!

Try it online!

6 added 324 characters in body
source | link

JavaJava (OpenJDK), 150 143 148164 bytes

int f(int a){int i=(int)Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")&&new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}
int f(int a){if(a<1)return 2;int i=(int)Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")||new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

i has at least n-1 digits. The for loop checks if there are enough 2s at the start, the That second part is a primality checking regex there matches composite unary integers.

Edit: Fixed an error caused by Math.pow returning a double and me assigning it to int iTry it online!

Java, 150 143 148 bytes

int f(int a){int i=(int)Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")&&new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

i has at least n-1 digits. The for loop checks if there are enough 2s at the start, the second part is a primality checking regex.

Edit: Fixed an error caused by Math.pow returning a double and me assigning it to int i

Java (OpenJDK), 164 bytes

int f(int a){if(a<1)return 2;int i=(int)Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")||new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

That second regex there matches composite unary integers.

Try it online!

5 added 109 characters in body
source | link

Java, 150 143143 148 bytes

int f(int a){int i=Mathi=(int)Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")&&new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

i has at least n-1 digits. The for loop checks if there are enough 2s at the start, the second part is a primality checking regex.

Edit: Fixed an error caused by Math.pow returning a double and me assigning it to int i

Java, 150 143 bytes

int f(int a){int i=Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")&&new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

i has at least n-1 digits. The for loop checks if there are enough 2s at the start, the second part is a primality checking regex.

Java, 150 143 148 bytes

int f(int a){int i=(int)Math.pow(10,a-1);for(;!(i+"").substring(0,a).matches("2+")&&new String(new char[i]).matches(".?|(..+?)\\1+");i++);return i;}

i has at least n-1 digits. The for loop checks if there are enough 2s at the start, the second part is a primality checking regex.

Edit: Fixed an error caused by Math.pow returning a double and me assigning it to int i

4 Mixed up conditionals in for loop ;-;
source | link
3 added 4 characters in body
source | link
2 deleted 19 characters in body
source | link
1
source | link