6 added 12-byte version
source | link

Test it online! It finishes within two seconds on my machine for all inputs up to 14, and after that it naturally loses precision (JavaScript only has integer precision up to 253).


In the latest version of Japt, this can be 12 bytes:

_n j}b!+'2pU   // Implicit: U = input integer
_   }b         // Return the first non-negative bijective base-10 integer that returns
               // a truthy value when run through this function, but first,
      !+       //   prepend to each integer
        '2pU   //   a string of U '2's.
               // Now back to the filter function:
 n j           //   Cast to a number and check for primality.
               // Implicit: output result of last expression

Test it online! It finishes within half a second on my machine for all inputs up to 14.

Test it online! It finishes within two seconds on my machine for all inputs up to 14, and after that it naturally loses precision.

Test it online! It finishes within two seconds on my machine for all inputs up to 14, and after that it naturally loses precision (JavaScript only has integer precision up to 253).


In the latest version of Japt, this can be 12 bytes:

_n j}b!+'2pU   // Implicit: U = input integer
_   }b         // Return the first non-negative bijective base-10 integer that returns
               // a truthy value when run through this function, but first,
      !+       //   prepend to each integer
        '2pU   //   a string of U '2's.
               // Now back to the filter function:
 n j           //   Cast to a number and check for primality.
               // Implicit: output result of last expression

Test it online! It finishes within half a second on my machine for all inputs up to 14.

5 added 45 characters in body
source | link

Japt, 20 bytes

L²o@'2pU +Xs s1)nÃæj

Test it online! It finishes within two seconds on my machine for all inputs up to 1314, and after that it naturally loses precision.

Many thanks to @obarakon for working on this :-)

Explanation

                       // Implicit: U = input integer, L = 100
L²o                    // Generate the range [0...100²).
   @             Ã     // Map each item X through the following function:
    '2pU               //   Take a string of U "2"s.
         +Xs s1)n      //   Append all but the first digit of X, and cast to a number.
                       // If U = 3, we now have the list [222, 222, ..., 2220, 2221, ..., 222999].
                  æ    // Take the first item that returns a truthy value when:
                   j   //   it is checked for primality.
                       // This returns the first prime in the forementioned list.
                       // Implicit: output result of last expression

Japt, 20 bytes

L²o@'2pU +Xs s1)nÃæj

Test it online! It finishes within two seconds on my machine for all inputs up to 13.

Many thanks to @obarakon for working on this :-)

Explanation

                       // Implicit: U = input integer, L = 100
L²o                    // Generate the range [0...100²).
   @             Ã     // Map each item X through the following function:
    '2pU               //   Take a string of U "2"s.
         +Xs s1)n      //   Append all but the first digit of X, and cast to a number.
                       // If U = 3, we now have the list [222, 222, ..., 2220, 2221, ..., 222999].
                  æ    // Take the first item that returns a truthy value when:
                   j   //   it is checked for primality.
                       // This returns the first prime in the forementioned list.
                       // Implicit: output result of last expression

Japt, 20 bytes

L²o@'2pU +Xs s1)nÃæj

Test it online! It finishes within two seconds on my machine for all inputs up to 14, and after that it naturally loses precision.

Many thanks to @obarakon for working on this :-)

Explanation

                       // Implicit: U = input integer, L = 100
L²o                    // Generate the range [0...100²).
   @             Ã     // Map each item X through the following function:
    '2pU               //   Take a string of U "2"s.
         +Xs s1)n      //   Append all but the first digit of X, and cast to a number.
                       // If U = 3, we now have the list [222, 222, ..., 2220, 2221, ..., 222999].
                  æ    // Take the first item that returns a truthy value when:
                   j   //   it is checked for primality.
                       // This returns the first prime in the forementioned list.
                       // Implicit: output result of last expression
4 bug fix :(
source | link

Japt, 16 1520 bytes

Lo@'2pUL²o@'2pU +X+Xs s1)nÃæj

Test it online!Test it online! It finishes within a secondtwo seconds on my machine for all inputs up to around 1013.

Many thanks to @obarakon for working on this :-)

Explanation

                       // Implicit: U = input integer, L = 100
LoL²o                    // Generate the range [0...100100²).
   @             Ã     // Map each item X through the following function:
    '2pU               //   Take a string of U "2"s.
        +X +Xs s1)n      //   Append all but the first digit of X, and cast to a number.
                       // If U = 43, we now have the list [22220[222, 22221222, ..., 222299]2220, 2221, ..., 222999].
                  æ    // Take the first item that returns a truthy value when:
                   j   //   it is checked for primality.
                       // This returns the first prime in the forementioned list.
                       // Implicit: output result of last expression

Japt, 16 15 bytes

Lo@'2pU +X nÃæj

Test it online! It finishes within a second on my machine for all inputs up to around 10.

Many thanks to @obarakon for working on this :-)

Explanation

                  // Implicit: U = input integer, L = 100
Lo                // Generate the range [0...100).
  @         Ã     // Map each item X through the following function:
   '2pU           //   Take a string of U "2"s.
        +X n      //   Append X, and cast to a number.
                  // If U = 4, we now have the list [22220, 22221, ..., 222299].
             æ    // Take the first item that returns a truthy value when:
              j   //   it is checked for primality.
                  // This returns the first prime in the forementioned list.
                  // Implicit: output result of last expression

Japt, 20 bytes

L²o@'2pU +Xs s1)nÃæj

Test it online! It finishes within two seconds on my machine for all inputs up to 13.

Many thanks to @obarakon for working on this :-)

Explanation

                       // Implicit: U = input integer, L = 100
L²o                    // Generate the range [0...100²).
   @             Ã     // Map each item X through the following function:
    '2pU               //   Take a string of U "2"s.
         +Xs s1)n      //   Append all but the first digit of X, and cast to a number.
                       // If U = 3, we now have the list [222, 222, ..., 2220, 2221, ..., 222999].
                  æ    // Take the first item that returns a truthy value when:
                   j   //   it is checked for primality.
                       // This returns the first prime in the forementioned list.
                       // Implicit: output result of last expression
3 golfed a byte
source | link
2 added explanation
source | link
1
source | link