[Question]
  [
A near-repdigit number is a positive integer where all the digits are the same, except one. For example 101 and 227 are near-repdigits. A near-repdigit prime is a near-repdigit that is also prime. For example:
101, 113, 131, 151, 181, 191, 199, 211, 223, 227, 229, 233, 277, 311, 313, 331, 337, 353, 373, 383, 433, 443, 449, 499, 557, 577, 599, 661, 677, 727, 733, 757, 773, 787, 797, 811, 877, 881, 883, 887, 911, 919, 929, 977, 991, 997, 1117, 1151, 1171, 1181, 1511
These are all near-repdigit primes.
The smallest near-repdigit prime has two digits, but it is an open mathematical question whether there exists a near-repdigit prime for every possible number of digits larger than 2. It is conjectured, by me, that the answer is in fact yes.
# Task
For each integer `n` where `n >= 2`, compute a near-repdigit prime with `n` digits.
Your code can either output a near-repdigit prime with 2, 3, ... digits or, as they are easily compressible, output a compressed representation of each number. For example, any near-repdigit can be represented by four smaller numbers. The first is the number of digits, the second the majority digit, the third the minority digit and the fourth the location of the minority digit. You can choose whichever representation you prefer.
## Primality testing
There are [many different ways](https://en.wikipedia.org/wiki/Primality_test) to test if a number is prime. You can choose any method subject to the following conditions.
* You can use any primality test that is guaranteed never to make a mistake.
* You can use any well-known primality test which hasn't been proved to be correct but for which there is no known example number for which it gives the wrong answer.
* You can use a probabilistic primality test if the probability of giving the wrong answer is less than 1/1000.
I will test your code for 5 minutes on my ubuntu 22.04 machine, but please quote how high you get on your machine in your answer.
This challenge is judged per language.
In the *very* unlikely event that you find a number of digits n for which there is no near-repdigit prime, I will award a 500-rep bounty and you will get mathematical immortality.
# Results so far
* **n=1291** by Kirill L. in **Julia**
* **n=1291** by c-- in **C** with gmp
* **n=1232** by jdt in **C++** with gmp
* **n=972** by Kirill L. in **Julia**
* **n=851** by alephalpha in **Pari/GP**
* **n=770** by ZaMoC in **Wolfram Language** (not tested on my PC)
* **n=722** by gsitcia in **Pypy/Python**
* **n=721** by jdt in **C++**
* **n=665** by c-- in **C++**
* **n=575** by Seggan in **Kotlin**
* **n=403** by Arnauld in **nodejs**
* **n=9** by py3\_and\_c\_programmer in **Python**
  
[Answer]
# [Julia](https://julialang.org) n = 972 (single-threaded)
```
using Primes, ThreadPools
function nrdprime(n) 
  a = fill(0, n)
  for j = 1:9
    a[1:n] .= j
    for k = n:-1:1, l = 0:9
      if j == l continue end
      if l == 0 && k == 1 continue end
      a[k] = l
      if iseven(a[n]) continue end
      x = parse(BigInt, join(a))
      if isprime(x)
        print("$n $j $l $k\n")
        return x
      end
      a[k] = j
    end
  end
  println(n, " has no answer")
end
@qthreads for i = 2:2000 nrdprime(i) end
```
Uses Primes.jl package (`import Pkg; Pkg.add("Primes")`). According to the source code, it relies on Miller-Rabin algorithm implementation from libgmp library.
UPDATE: Added multithreading with ThreadPools.jl (`import Pkg; Pkg.add("ThreadPools")`). Compared to Base.Threads module, using a pool allows scheduling calculations in a more convienient way for our use case. In order to take advantage of concurrency, run the program with `julia --threads N`, setting the number N in accordance with your CPU specification.
The output was changed to compressed form (`n major minor position`) and I also tweaked the code a bit to reduce the number of array allocations, but it looks like this isn't really a bottleneck.
[Try it online!](https://tio.run/##ZZDBbsMgDIbvfYpfOVQgZRLZrUi97LZnqHpALdmcMFMRsuXtMzMaVVMv2P79@Qc8zIHcuvYzXzJFBqfrLdGXV6yxA/qYMOCIzh5ajJKwfels1yJIbuxBEID6whxFu0TOxLOH5@vWCqVlsN@XeXF6hpx49RSCGlqwrtJpPIsaNhOa/Ldn5U581s8Gi6A3lyav3ujjnXOLIZLQWj/m66@WqgBScg6suEWDRgbuMdzjuIHJ5zkxlr@yXljPfw6fbgJHOJ5@fGr0TpC17I7kZa@2M8Y8Nku6OKy/ "Julia 0.4 – Try It Online") for `n` up to about 550 in 1 min, using an ancient version of Julia that still has primes-related functionality integrated in base, and thus available on TIO.
[Answer]
# [C++ (gcc)](https://gcc.gnu.org/) with boost, n = 595
~354 digits in 60 seconds on TIO.
~595 digits in 5 minutes on my Windows machine, compiled with MSVC.
```
#include <atomic>
#include <chrono>
#include <iostream>
#include <mutex>
#include <thread>
#include <unordered_map>
#include <boost/multiprecision/miller_rabin.hpp>
namespace mp = boost::multiprecision;
std::atomic<int> digits{ 2 };
std::mutex mtx;
std::unordered_map<int, mp::cpp_int> results;
mp::cpp_int calcPrimes(int n)
{
    char buf[10000] = { 0 };
    for (int i = '1'; i <= '9'; i+=2)
    {
        std::memset(buf, i, n);
        for (int j = '0'; j <= '9'; j++)
        {
            if (j != i)
            {
                for (int k = 0; k < n; k++)
                {
                    if (k > 0 || j > '0')
                    {
                        buf[k] = j;
                        mp::cpp_int num(buf);
                        if (miller_rabin_test(num, 10))
                        {
                            return num;
                        }
                        buf[k] = i;
                    }
                }
            }
        }
    }
    return 0;
}
void threadJob()
{
    for (;;)
    {
        int n = digits.fetch_add(1);
        auto result = calcPrimes(n);
        mtx.lock();
        results[n] = result;
        mtx.unlock();
    }
}
int main() {
    int count = 1;
    const auto start = std::chrono::steady_clock::now();
    const auto tc = std::thread::hardware_concurrency();
    std::vector<std::thread> threads;
    for (int j = 0; j < tc; j++)
        threads.emplace_back(threadJob);
    for (;;)
    {
        std::this_thread::sleep_for(std::chrono::milliseconds(50));
        mtx.lock();
        auto seconds = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - start);
        for (const auto& result : results) {
            std::cout << std::setfill(' ') << std::setw(3) << result.first << ": " << result.second;
            std::cout << "  time: " << seconds.count() << " sec, count: " << count++ << "\n";
            if (result.second == 0)
            {
                std::cout << "Mathematical Immortality!!!";
                exit(1);
            }
        }
        results.clear();
        mtx.unlock();
    }
    for (int j = 0; j < tc; j++)
        threads[j].join();
}
```
[Try it online!](https://tio.run/##lVRNb9swDL37V6gZsNjIR5MWO8x2ct@AYbt3haHISiPHkgxJ7ge6/PVllGUncpq0mA6JRfGRTxQfSVVNHgjZ7z8xQco6pyjFRnJGlsHRQjZKCulbmNRGUcx9G68NffYNZgMuuW@phVQ5VTTPOK78g5WEgNe8Lg2rFCVMMymuOStLqjKFV0xMNxUAAoE51RUmFPEKLVADi@M@LgkCbfI4dvdImTBLlLMHZvQrukG7xJ02bBE3z@2@R82CxpAijklVZU0ERTVk0RDcMyOCS/JLMSAV2q2IgtcAwSIbrNCqXt/NZ7Dugeormtnc9nAtFWrcGdiH82ECHyl8fbVfo8VN1Hi5QHY5vpRrakKIOUZsDJmSw/khXmHjzSBKcYhXjEbRwfEY0i62RmGBrhaIRT1736uXYAsJZgn8pUjAnx/7MrrLtUVLqMGfP8BuaWlGZz3P4@2y5dzaUhbJRR//bUTNbbmiy96Wld9kmaHahIAbo/ksii7iLnO0S1FTK2HTX868@/iW7Dz6LbJvOe7cl/ttOc2SYBcEj5LlyInzu1yFXc82r5wkp93XlBL4OAlN19SQTYbzPJx7lcW1ka1EwNVThd@nILZpKck29GytrO6EvbLb9AG18CE7y98y4piJMGppNkqUtbC5586RSKGNo6UNVvakkZEbZXGsDdz@JSM2eBwL@dRl8ICGdChXrDgGVedPWNEMvEitFBXkpQM2jo@UGKlSD7RsK61PtF84KYFSIc@JTlvElPKqhFmXrTBU4PBgUfLec7Wpmc460rqktMrAPexVwDY@0xRukuvwC7T7@w/lSuncT4uZ1wobmLwZwdqk/To7xDL8qPpo4h7qdK4d3@Nz12Bx1zXRiRJdDlkblKZuAyNzDfcMh2gY@can8LbZu0DTNVO6AQ1iNPDsjn1yOckAHgv6vEW1l502vRhGzgGMY9edrVfzPRo1p7/FIHkzlHvJ0QL65KMB3ef0A5sN5fAioEP0jXOpDC6Zebm6uhq8HSr0mZmels9NEU@qU1JSrMLofZn@b6/fFffTQlpN2xG13/8l6xI/6P3k5@1@Ujmnfw "C++ (gcc) – Try It Online")
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), at least n=116
```
ƛkdn1-v*9ʀẊ'ƒc¬;9ʀẊƛf÷$Ṁ;U'⌊=$⌊æ∧;h
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJUIiwiIiwixptrZG4xLXYqOcqA4bqKJ8aSY8KsOznKgOG6isabZsO3JOG5gDtVJ+KMij0k4oyKw6biiKc7aCIsIiIsIjIwMCJd)
A simple modification of my answer to a CMC for near-rep numbers of length 8.
It can do up to n=116 in a minute on the online interpreter. Maybe more depending on where you run it.
The score here is cumulative total. If you want individual limits of `n`, it can handle at least n=200 in less than 10 seconds with a few modifications.
I'll explain this properly a bit later, but basically:
`kd7v*9ʀẊ` gets the Cartesian product of each digit from 0 to 9 repeated n times and the range [0, 9].
`'ƒc¬;` keeps items where the digit from the range isn't in the string (because this Cartesian product is [repeated digit, number to insert at every position])
`9ʀẊ` is once again Cartesian product with range [0, 9]. It gives a list of [[repeated digit, number to insert], location to insert]
`ƛf÷$Ṁ;` flattens each list, swaps the order of the number to insert and the position and performs the insertion
Finally, `'⌊=$⌊æ∧;` uniquifies the result and keeps only those invariant under conversion to int and which are also prime.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), n = 351
Reached \$n=351\$ in 5 minutes on my laptop. Reaches \$n\approx 250\$ in 1 minute on TIO.
Uses a Miller-Rabin primality test with 10 rounds.
**NB**: Because the challenge allows a probability of false positive as high as 1/1000, we could actually perform fewer rounds -- at least until \$n\$ becomes really large. This would however not improve the performance drastically, as most of the computation is used for processing non-primes for which the test is most likely to fail on the first round anyway.
```
const ROUNDS = 10;
function modpow(k, e, m) {
  let r = 1n;
  while(e) {
    if(e & 1n) {
      r = (r * k) % m;
    }
    e >>= 1n;
    k = (k * k) % m;
  }
  return r;
}
function millerRabin(sz, n, k) {
  let d = n - 1n, s = 0n;
  do {
    s++;
    d >>= 1n;
  } while(!(d & 1n));
  while(k--) {
    let a;
    do {
      a = BigInt([...Array(sz)].map(_ => Math.random() * 10 | 0).join(''));
    } while(a < 2n || a > n - 1n);
    if(millerRabinIteration(n, d, s, a)) {
      return false;
    }
  }
  return true;
}
function millerRabinIteration(n, d, s, a) {
  let x = modpow(a, d, n);
  if(x == 1n || x == n - 1n) {
    return false;
  }
  for(let i = 0n; i < s - 1n; i++) {
    x = modpow(x, 2n, n);
    if(x == n - 1n) {
      return false;
    }
  }
  return true;
}
let ts = Date.now(), time;
for(let sz = 2; (time = Math.round((Date.now() - ts) / 1000)) < 300; sz++) {
  console.log(time + 's', 'n=' + sz, search(sz));
}
function search(sz) {
  for(let i = 1; i <= 9; i++) {
    let a = Array(sz).fill(i);
    for(let j = 0; j <= 9; j++) {
      for(let k = j ? 0 : 1; i !=j && k < sz; k++) {
        a[k] = j;
        let n = BigInt(a.join(''));
        if(
          n % 2n && n % 3n && n % 5n && n % 7n &&
          millerRabin(sz, n, ROUNDS)
        ) {
          return n;
        }
        a[k] = i;
      }
    }
  }
  return false;
}
```
[Try it online!](https://tio.run/##lVRNb9swDL3nV7CHxtLieE6LYdicZNjQSw/bgA47FcWgxUrjL7mQlbXL4t@ekbZsK0F22CVhRPKR75FMKn6JaqWTJzNVZSwPh1WpKgN3X79/ufkGC5iF0Wi03qqVSUoFRRk/lc8s80H6UHD4MwLIpQFNkQojAZ43SS6ZbH0AyZpJGKOze4AmmGl4BRmHSyii5rluPiUsly0S/cooMDsKpDAtzVYr0NGodltL8lzqO/EzUaza@aB8SusajBFKwRShfajQDpsScWmbqiaTtmTsNFBbLhcsbhlwh2A2nXaMCF80LgcRQGCZT8njrTLsPgiCj1qL39gZfwgK8cR@wGIJn4XZBFqouCwYR56zEPYQ8iAtkYTnUcFGG1tTwByuFOz3iL20dLgtjDo7CtwaqQXJwpBvjJR9ENyZQKvgWuSVHOR3tDV6K/8p71nwXukXpG3XRDRu2yI2iC7Slgg0pmVg2zptqqasdakZoSbtzPB7jvOjNLQnky7XKfrio0ZtVavLmVr/IwGVN7QzN8LIQGEJ7oNJCkmHYdurdui/ioDRO5rtYMutihkb0rAFU3F4jXMOQxzHHK7DMMLkjgjdXpnLIC8fW6QJeJXng6cWHtq01pUUerWhPeLHAxocDZQr3KzRbQHvjjRr1ha9/WIGa5wxS7qN6hBSkj7CrxYhHRCGGLrUFD5ACO/baheLFMZjfMdx7SLI3CQ8jfvsgTKi/oVA1HAw4vQE7Ch7GzD6ko4Bi5B13VtveustWU7GmX@I9m@O90Fuk/0mqKGF@pRC0vnqcztkt6s@HP4C "JavaScript (Node.js) – Try It Online")
[Answer]
# [Python 3 (PyPy)](http://pypy.org/), n = 808
~432 digits on TIO in one minute (no multiprocessing)
~808 digits on my computer in 5 minutes
~697 digits on my computer in 5 minutes on 1 core
Uses [Baillie-PSW primality testing](https://en.wikipedia.org/wiki/Baillie%E2%80%93PSW_primality_test).
Avoids testing any multiple of 2, 3 or 5.
```
# aab -- a in [1,2,3,4,5,6,7,8,9]
#     -- b in [1,3,7,9]
# aba -- a in [1,3,7,9]
#     -- b in [0,1,2,3,4,5,6,7,8,9]
# baa -- a in [1,3,7,9]
#     -- b in [1,2,3,4,5,6,7,8,9]
# b + a*(n-1) != 0 mod 3
aab = [[(a,b) for a in [1,2,3,4,5,6,7,8,9] for b in [1,3,7,9] if (b + a*(n-1))%3] for n in range(3)]
aba = [[(a,b) for a in [1,3,7,9] for b in [0,1,2,3,4,5,6,7,8,9] if (b + a*(n-1))%3] for n in range(3)]
baa = [[(a,b) for a in [1,3,7,9] for b in [1,2,3,4,5,6,7,8,9] if (b + a*(n-1))%3] for n in range(3)]
def f(n):
    A = (10**n-1)//9
    # aab
    for a,b in aab[n%3]:
        if baillie_psw(a*A + (b-a)): return (n,a,b,0)
    # baa
    B = 10**(n-1)
    for a,b in baa[n%3]:
        if baillie_psw(a*A + (b-a)*B): return (n,a,b,n-1)
    # aba
    for k in range(1, n-1):
        B = 10**k
        for a,b in aba[n%3]:
            if baillie_psw(a*A + (b-a)*B): return (n,a,b,k)
    sike
def main():
    import multiprocessing
    import time
    t = time.time()
    for i in range(3, 2500, 2):
        if baillie_psw(i): small_primes.append(i)
    with multiprocessing.Pool(multiprocessing.cpu_count()-1 or 1) as pool:
        for i in pool.imap(f, range(2, 10000)):
            print(i, time.time() - t)
def baillie_psw(n):
    for p in small_primes:
        if n == p: return True
        if n%p == 0: return False
    return strong_pseudoprime(n) and lucas_prime(n)
small_primes = [2] # calculated out to 3000 in main
def ds(d):
    s = 0
    while d%2 == 0:
        s += 1
        d //= 2
    return d,s
def strong_pseudoprime(n):
    n1 = n-1
    d,s = ds(n1)
    x = pow(2,d,n)
    if x == 1 or x == n1: return True
    for _ in range(s):
        x = (x*x)%n
        if x == n1: return True
    return False
# code from https://en.wikipedia.org/wiki/Jacobi_symbol
def jacobi(D, n):
    D %= n
    t = 1
    while D:
        while D%2 == 0:
            D //= 2
            r = n%8
            if r == 3 or r == 5: t = -t
        n,D = D,n
        if D%4 == 3 == n%4: t = -t
        D %= n
    if n == 1: return t
    return 0
def sign(n):
    if n > 0: return 1
    if n < 0: return -1
    return 0
def isqrt(n):
    if n < 2: return n
    k = n//2
    k1 = n
    while k < k1:
        k1 = k
        k = (k+n//k)//2
    return k
def is_square(n):
    np = isqrt(n)
    return np*np == n
def UVQ(P, Q, D, k, m):
    u,v,q = 0,0,-1
    B = f'{k:b}'
    B1 = B.rstrip('0')
    for i in B1:
        u,v,q = (u*v)%m,(v*v-2*q)%m,(q*q)%m
        if i == '1':
            a = P*u + v
            b = D*u + P*v
            if a%2: a += m
            if b%2: b += m
            u,v,q = (a//2)%m, (b//2)%m, (Q*q)%m
    if u == 0 or v == 0: return True
    for _ in range(len(B)-len(B1)-1):
        u,v,q = (u*v)%m,(v*v-2*q)%m,(q*q)%m
        if v == 0: return True
    return False
def lucas_prime(n):
    for D in [5, -7, 9, -11, 13, -15, 17, -19, 21, -23, 25, -27, 29, -31, 33, -35, 37, -39, 41, -43]:
        J = jacobi(D, n)
        if J == -1: break
        if J == 0 and D%n: return False
    else:
        if is_square(n): return False
        else:
            while J != -1:
                D = -D - 2*sign(D)
                J = jacobi(D, n)
                if J == 0 and D%n: return False
    P = 1
    Q = (1-D)//4
    if Q == -1: P = Q = 5
    return UVQ(P, Q, D, n+1, n)
if __name__ == '__main__':
    main()
```
[Try it online!](https://tio.run/##nVZZb@M2EH73r2BRCKYUKtZhNxtjXSCBsEWDLpD0egkCgYrkrCqJVnQ4CYr97ekMdVGRDST1g0WOZr755iKVv1TfdsI185f85fU1zvJdUZEyfhA8nc2a52nzoO3uj19/ufjt96@MpDwLQk4Mfx09xxXV9U6fp7zI6Gqlz2Y/Es4DYpqEk1iQW5s5zGVLtmI/sTP2iZ3fgQb@QCNoNVx4I@U84KplLx/pW@wgZsDfYXvYkpwQblBh2jr5YUMsku1C4s5mGMeG3N5SzgKdbHfF0ZDky3E0JN4SqiDrmtuoCVQruHiIqKvfzTDkw05anAH6UODvdYPZeaeb/@9kFkZbsqVCX88w6xfgkdqWYaDNYnEuhbI95EqSYNIniG4FgDZ2@AOPAY/TNI78vHyi3LgA9zQwua6vSRFVdSEIFQzsmaW3wBCjXF2CX3Qrub51BUrvdmVcTpz1kLJZe/BkSITNCCoN@B2dpJeokQdv6XyYUtIQKuMkaiqQ8VjQlkA73lWcRXJfARncnOIfHbITK5VkxFlZFvzrR5MUA4sy42nq5wUAlac8zyMRgvwQosMgAfBT8MBMVHQLBkzlQ0xS6U0UqruuoxA3R1zV94ikIJsNyfsU/VnU0ei1lqOC1St84WnZaLSCsip24gG8RnW4kw7AO@EiJGl9z0u/E8FRqXDA2XLuoCnueXpfp7yKQrKrIe874kLgSBmr0kQWljRsA0JDS66evsVpRELNafj1pEtyAu3Tb0OyWGyIozIOWdngHqTeIAkbHEFbyg0YwA5YiLaXn2Gb756gTiETjQhy9YxMbAIplythT7OK9fCHOpdKgRGTPhvPuibUAhyFGtVDhvMPv98FMfVgnlpcj2hg3PexrSTOGzy3gkkmG4Qhfd2vwNRon94OYIHmLoYvV6u19GlWvV7BBPPQlnlsFKOnLRtbDFVbTgyVMLqOHRJSqdmw2sLCJduXUpr8rLSwPYg/K@K22GOkuHwsqjHUZ@L0Ng2pBINaLJosJbJzlEwnYJHYQ1qlwnC2oTFNTsA@0TuMFj3pOPjlY80LpTthKHtqqoXIDSEHtp2cv/6@odeM3DACXZEwkrUANduzRxwlZrE2bjx1t/N/k3Xwfd4IkOflaQFTEud0bs3fHFWXSkwdHq2Nva5ljO6NvekYj3L9KJ9qwWOkOLfn417DC/faqOHk3o/k@FHhSfm1sX/bdVyDanCc@WxyI@CrYPqqJ8sh38gQbop@dTOQBYhajgT29H58DB6b6DQS9FI35cPWR9faB3N0zOF07sfn7HDwe/LrZMWIecbIOTxsuGptFxcgtM9wAWIHpKYjLzFcgNhBZRfELiq7IHZR2QXxEpWX6vV7BSGpJ48awxXGYMKsBkXEk8kbS14TniYO3C4RLEYX1WgKpvpTm2ECr/Ar1bTHr5qDBeQe3KGOIY8MT5@oHA3vI8Fc94fvjfzEMz0Y9WXXZDddllANFVZqoUcjLE5sSWIGZr4veBb5vpwl38fr0vfbkWq@aF5f/wM "Python 3 (PyPy) – Try It Online")
In profiling I found that about 97% of the time was spent in `strong_pseudoprime`, specifically the line `x = pow(2,d,n)`.
I wanted to avoid using external libraries in my answer, but it is possible to improve the speed significantly by using gmpy2 (or gmpy\_cffi with pypy), and replacing the line with `x = pow(mpz(2),d,n)`. This achieved ~1050 digits in 5 minutes.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), n=770
```
(n = #;
  r = RandomChoice[{1,3,7,9}];
  While[! 
     PrimeQ[p = 
       FromDigits@
        RandomSample[
         Join[Table[r, 
           n - 2], {r1 = 
            RandomChoice@Complement[Range[0, 9], {r}]}, {r}]]] || 
    r1 == r];
  i = IntegerDigits@p;
  f = First /@ Reverse@SortBy[Tally@i, Last];
  Flatten[{n, f, Position[i, f[[2]]]}]) &
```
[Try it online!](https://tio.run/##TZBRS8MwEMff9ylOBFGI2FVEhhSKk4Liw9wEH448xJm2YU1S0kMYXT97vbZTl5ccv@R@@V@solJbRWar@iLpLx0kcP4wAwhcrJX78nZZerPV2M7FrbgXi04Oxx@lqTSeAZe8VsFY/YY190wAIAvePpnCUJP@oqNvo2zNvX8UXrxx@K4@GQYB/xzAwTXEUkAb5ifqE9eULV36QWm1I2ReaIwELMa@TnbTJiUcDpNikCUQxjkMe58d6UKHY9p6wDnjzISG4CaFtf7WodHpxgd63HPSqtqnRsCramiUZJUi0g5bJyAXsPKNIeMd8p0cMea3O3kFF/00I3@WI8ACd1KKdidicRdFnZz1Pw "Wolfram Language (Mathematica) – Try It Online")
n=500 in 1min  
n=770 in 5min
[Answer]
# [Kotlin](https://kotlinlang.org), n = 575
```
fun main() {
    var n = 2
    while (true) {
        println(primesForN(n))
        n++
    }
}
fun primesForN(n: Int): String {
    for (major in '1'..'9') {
        // Java's String.repeat is much faster than Kotlin's
        @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
        val digits = (major.toString() as java.lang.String).repeat(n - 1)
        for (minor in '0'..'9') {
            if (major == minor) continue
            if (major.isEven()) {
                if (minor.isEven()) continue
                val number = digits + minor
                if (number.toBigInteger().isProbablePrime(10)) {
                    return number
                }
            } else {
                for (i in 0 until n - 1) {
                    if ((i == n - 1 && minor.isEven()) || (i == 0 && minor == '0')) continue
                    val number = digits.substring(0, i) + minor + digits.substring(i)
                    if (number.toBigInteger().isProbablePrime(10)) {
                        return number
                    }
                }
            }
        }
    }
    return "No near-repdigit primes found for n = $n"
}
fun Char.isEven() = this == '0' || this == '2' || this == '4' || this == '6' || this == '8'
```
[Try it online!](https://tio.run/##pZRNb9pAEIbv/hUjFMU2NMZEVdRGQiqliZSGACrc0ZIs9qb2GO0HPTT8djrrNV/BtIfugfV435195xmzPwudCdxsFgYhZwKDEH57QGPFJCB04bqMfqUi4xBoafhWYMdSCtQZBjTnXN0XchhgGO6WsdUqn9fe2vPazaYHTegX@dJoroBlGSBn8kry5YtIhAaXBRaFBAaJWHGEjGOiU8CItrY9a/LwqFt4QB3ewkSTj6TyZbcHOXulSSD4HT@K/M/@oet2G76zFfNVtTEiB5xpEApy85zCginNJeiUITyWfHy12/xlYpZLyZUKGuNBb3o/@vE06w96k8nsqTce332bTUezx9F08DBs7EGsWAZljYqIOnORLtzpRJwpeCVDUcbIjHsbVqYChCvo7DO56gRW1cWn1dkhFlsE3S6U6hCeC9QCDa8XRkLdEfAgfJ9qp7JZDlS16ba1osnnRLC7LbrlTNQmdlrC8VUk1E6ecBmEdNBYFnM2z/jYNjzoxLXO7JBcG4nVmSeK9dGbNfBM8ZpEJVdhmcZgqDKqoQR/5kxrnOREt5TB5SW8B/T2Bk4R71ZtRC37G70zBCNl5sp9LvEHEOGWKM0nAhGetfzfrP/N@5R5TRe84yf3W@VtDItz94LBl7JR9l66wIa9VeyV0E/ZHjwt6ZT@yQ617cIuvD4OPx6HN8fhJ3@z@QM "Kotlin – Try It Online")
Gotta love Kotlin's `CharRange`. The `isProbablePrime` test is a Miller-Rabin test that has a \$\frac{1}{2^{10}}\$ chance of failing. For ease, [here](https://drive.google.com/file/d/1-3rczmlzqyqlrN5eYSoR66JTAmukwih2/view?usp=sharing) is the jar file.
[Answer]
# [C++ (clang)](http://clang.llvm.org/) with [GMP](https://gmplib.org/) n = 1164
To be compiled with the following flags: -O3 -lgmp -lpthread.
```
#include <atomic>
#include <chrono>
#include <cstring>
#include <iostream>
#include <mutex>
#include <thread>
#include <map>
#include <vector>
#include <gmp.h>
struct result
{
    char major;
    char minor;
    int pos;
};
std::atomic<int> digits{ 2 };
std::atomic<bool> timeOut{ false };
std::mutex mtx;
std::map<int, result> results;
result calcPrimes(int n)
{
    mpz_t x;
    char buf[10000] = { 0 };
    for (char i = '1'; i <= '9'; i+=2)
    {
        std::memset(buf, i, n);
        for (char j = '0'; j <= '9'; j++)
        {
            if (j != i)
            {
                for (int k = 0; k < n; k++)
                {
                    if (k > 0 || j > '0')
                    {
                        buf[k] = j;
                        mpz_init_set_str(x, buf, 10);
                        if (mpz_probab_prime_p(x, 10))
                        {
                            return { i, j, k };
                        }
                        buf[k] = i;
                    }
                }
            }
        }
    }
    return {};
}
void threadJob()
{
    while (!timeOut)
    {
        int n = digits.fetch_add(1);
        auto result = calcPrimes(n);
        mtx.lock();
        results[n] = result;
        mtx.unlock();
    }
}
int main() {
    int count = 0;
    int maxTime = 5 * 60;
    const auto start = std::chrono::steady_clock::now();
    const auto tc = std::thread::hardware_concurrency();
    std::vector<std::thread> threads;
    for (int j = 0; j < tc; j++)
        threads.emplace_back(threadJob);
    for (;;)
    {
        std::this_thread::sleep_for(std::chrono::milliseconds(50));
        mtx.lock();
        auto seconds = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - start);
        if (seconds.count() >= maxTime)
        {
            timeOut = true;
            mtx.unlock();
            break;
        }
        for (const auto& result : results) {
            std::cout << result.first << ": " << "major: " << result.second.major << ", minor: " << result.second.minor << ", pos: " << result.second.pos;
            std::cout << ", time: " << seconds.count() << " sec, count: " << ++count << "\n";
        }
        results.clear();
        mtx.unlock();
    }
    for (int j = 0; j < tc; j++)
        threads[j].join();
    std::cout << "Time: " << maxTime << " seconds\n";
    std::cout << "Count: " << count << "\n";
}
```
[Try it online!](https://tio.run/##lVbBcpswEL3zFWo600LtME476UzB4dJbL@mht7TDyEK2hUFiJJE4Tf3rdVdIYOHYyZSDkVbvrd6udoVJ01ySCvPVfv@WcVK1BUVzrEXNSBYcLGQtBRcji9KS8ZVvYgJsFNe@rW413foGvQZIMYLgxp/eU6KF9C2ruonXWRCA95ZoJKlqKx08BQgessYS1bgUMvXmjPdzxjVqhEqDXWocFElig5vDQoYKtmJaPaGPCJb91YUQVYY0q@ltq5/QEleKDpguJlTrbT/HjXE3dcoy94ZNAztCBFfkuwRvKjSCeOTU183vXKOtJ33RLu@uZvD8QjfoCc3MpmZxKSQKOwSDhfdX71MYzGH0xYwmNx@jDmbdmscqo7WiOgSnU8SmsG86rB8clsbhDNyUg8NyMokG5MFnl9AlCkv05gaxaGQfo4YdTLgb2GCWwmuOOLx83@fZ/V4blEEW/vwBdZmRGZ1EnuabxyR0Y5JZpmcx5hgYZzqHZOVQZeF2irqcXc2i8yyjzjAbKRZ4AS8437wxXKBFZ2nnpZpHUt1KDicPx1VOIWe78wJ2rwfNTrOfM8eWw8yO7G@vDSTtguBesALZbv4mFmFf0g9rVlEUvnG9c1yWXfmDMNt58ZJqss5xUYRXXqZxq4VrIoB6zeMXMPRfXAmyCT2ba7w7bmK3kzGh5T5lZ@IwimrMeBg5mcZARMt1V7aDqcbbHyACjNfoA/rsVojgSlvBSmNpOF3n2QszSZSG/DzmxGybJFw89Ht7RE16lk1nkkBbFg9Y0hxQpJWScvLYEzugvSTnHilzZ6G8@8LILm3zQW/DPked7RgxrZsKE5ovMORmONLI85SmJ@8XvWYq70WritImB3g4ykDNqoopCpEUKryGznj5CG0qLfw4mUUrsWaC5wQrPR/n2TKy8LXso0t7UN6WppEdP@4OHlDZTX/g5y5CV@CgET5LdNxnz0tt6EzI1SYNnjeavY@HonjX13/SF3V0tL8NVICC@dxh4iWTqptfJOiie3efRjdxIBtq3K10mKn9YJ5GmRWHgu/oSUz3fT0rDYgmVY55nGcDMMapbTmHmkxsA5rVn/ziVL5cVmJSUSzD6OU2/9@OuCt/xaUwd4LXc0NAPw7h9JdCH4aJbRA8Zn314juKbrff/yXLCq/U/rKCfzv7y9tPMGqsmn8 "C++ (clang) – Try It Online")
[Answer]
# Python 3, computed till `n`=8
> 
> "Takes 51 seconds for 8 digits"
> 
> 
> 
Not a very interesting answer, I fear, and it's very slow.
```
from itertools import product as pt
def isprime(n):
    # This was borrowed from https://en.wikipedia.org/wiki/Primality_test
    # Modified to save bytes unnecessarily
    if n <= 3:return n > 1
    if not n%2 or not n%3:return False
    for i in range(5, int(n**.5)+1, 6):
        if not n%i or not n%(i+2):return False
    return True
def isnrep(n):
    if (not isprime(n)) or not (len(set(str(n)))==2):return False
    return list(str(n)).count(list(set(str(n)))[0])in[len(str(n))-1, 1]
    
def getnrepfor(n):
    x=[list(i)for i in eval("list(pt((1,2,3,4,5,6,7,8,9),"+("(0,1,2,3,4,5,6,7,8,9), "*(n-2))+"(1,3,7,9)))")]
    for i in range(len(x)):
        for j in range(len(x[i])):
            x[i][j]=str(x[i][j])
    x=[int("".join(i)) if isnrep(int("".join(i))) else '' for i in x]
    for i in x:
        if i!='':return i
    return 'It has been proven that for %d, there does not exist a near-repdigit' % n
```
Back to the bounty... I've found out that the amount of near-repdigit primes actually *increases* when the number of digits is increased. So I guess nobody will get that bounty.
Uses the 6k+-1 computation of primes.
I've updated this with an approach similar to lyxal's answer, but it hasn't produced much of a speedup. Oh well, guess esoteric languages are faster than those around 1991.
[Answer]
# [C (gcc)](https://gcc.gnu.org/) + [GMP](https://gmplib.org/), n = 1015 (w/ -j2)
* Compile with same flags as in [TIO](https://tio.run/##jVb7b5tIEP6dv2LUqinYkOL0Xg1JpFPrO0WK4lPanCrlLMRjwWvjXQ6WPHrKv36@2QcY25waS@Yxr29m@GYg8fIk2WxepySjjED4dfbH9Dr8PLu9@TiFn33fek1ZUjQpgbOI8uPFRU@Qr8tdQSkWFYnSXWEt0kjwNU0OxPvxUFTQeFfWMIpiKbPEU0kwTahF1SQCbkj5ieZUwD8W4K9hNc0ZSaHgLId1tAyGxJQNiUteB9ZzFzGwrFpEgiZbjCQqkrCs6JrU9q5vKvW1E7Qu95ymQBkVIWdovC6/hQIqXrrwAr/Rkse2vkKN1cJb34W3dBMMGkE0pXCBNeuhiqkLSxdWiNG6yZRru@96fXt15WjnbT1bg9roWuewJsJGOFfi93RRmmqv9uAY1IxXYFM4h0kAFM7O4UPQOag4XTAX9eNzOGkKGIE9wdNYeZ7De8dxDAFaPEwjbKhtipj4JpUOcaURV3Bm6tCo66bouZmTdHdhPF71QTqgJjZOKlHjQnt4HeYSMVcyX40InsxgaWoej5f74VXPM@V3jhEPdPKXcCYoa0hwoDVNHEhu6QSDONKjrHgcxZplYandfnSGsXMuOBCWDmMPN2Yf@9l6Wc79hmqfZ8tC7NOOYUlBomqXuypAj8AVEU3FwG4nChuuR6B7IKtnXAGWJYfPevn49uauoWHJH2T2ynziD8wJdqYz0FY9ZUrvyWOUiF2LD06XF4ys7X6IqrxF77ZUOTTqZuMli6iCuMnuTvwffpnfTX6aa7nZprjck1gfa23iwog3wsyqWVJ6kYdNrwXI7BNjpDJzADMLtgOOMdDkyET254EkPAr7lGdoYUJnRCQLyYSQPJYFTaiwjzQQNsuFNVnz6inkVUqqsCJF9EjSHj9KDNTflaynezdqM8aXA6@oeJKvA31R8ATr48yeeJSlRAaF0bvOFdP1LrCCMKNFSmTJn798mt1@CX@7vJpez4JDQ55luIfQ0B9Q4lNAjXwWsjme6fp8wJLFT0Lh1QwrYiKzD7xcqOk3wjMVz8fbV2@KBnr/v9grnAcXymOsW52ousOXnjMAWZG/EYr/T@pILHJPmDhWFyHjgmZPsh@Xv0//DK9n19Otk7R/wPYSyQED9ayZgs@iYfipgKSMC9K22gypHFvFeSzYWkeU2XghWZW4msWS@/d385b@UstLuWF4XGsY8yGCoyu0gDwKgqG1OxorjiqNdFJvBHX3sKCYj22jCQpzIvDC1tASFLu7PH2Fr5wL8PsErh8o0hakW1@cRDWBt8u3pzurziAi4amtU9nbjGrzSyOJcrBhY6xsteuA7cyiosCieZMv@szF76WoKcRuApnhEn5YkarCmpo6yskpvKnhzluq/OaKNarP/nwvPfKIQzn9eon0//Xy6vZmOrSge81UpXjeBS67Xm/aR5TgESlyZD44XDhC@53d3bdOiUDS2Ht0klvROHyfXr7k1maz8ZYn/yZZEeX1xpu933gGYuMV@F2Lx0r8Bw "C (gcc) – Try It Online").
* Specify number of threads as `-j jobs` depending on your hardware.
This uses [`mpz_probab_prime_p()`](https://gmplib.org/manual/Number-Theoretic-Functions) from GMP which uses a combination of a Baille-PSW test, and then Miller-Rabin tests.
Output: ***digits majority minority location(1-indexed)***.
```
#define _XOPEN_SOURCE 700
#include <aio.h>
#include <gmp.h>
#include <pthread.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
typedef struct RepDigit {
    unsigned long maj;
    unsigned long min;
    unsigned long pos;
} RepDigit;
static RepDigit calc_primes(unsigned long digits);
static void init_ones(mpz_t rop, unsigned long digits);
static void *job(void *);
RepDigit
calc_primes(unsigned long digits)
{
    mpz_t rep, digit, num;
    unsigned long i, j, k;
    mpz_inits(rep, digit, NULL);
    init_ones(rep, digits);
    mpz_init_set(num, rep);
    mpz_add(rep, rep, rep);
    for (i = 1; i <= 9; mpz_add(num, num, rep), i += 2ul * (1ul + (i == 3))) {
        mpz_set_ui(digit, 10);
        for (k = 1; k < digits; mpz_mul_ui(digit, digit,  10), ++k) {
            mpz_submul_ui(num, digit, i);
            for (j = k == digits - 1; j <= 9; ++j) {
                if (j == i)
                    continue;
                mpz_addmul_ui(num, digit, j);
                if (mpz_probab_prime_p(num, 5))
                    goto end;
                mpz_submul_ui(num, digit, j);
            }
            mpz_addmul_ui(num, digit, i);
        }
    }
end:
    mpz_clears(rep, digit, num, NULL);
    return (RepDigit) {i, j, digits - k};
}
void
init_ones(mpz_t rop, unsigned long digits)
{
    mpz_ui_pow_ui(rop, 10, digits);
    mpz_sub_ui(rop, rop, 1);
    mpz_divexact_ui(rop, rop, 9);
}
void *
job(void *arg)
{
    RepDigit p;
    unsigned long n;
    char buf[2048][16];
    struct aiocb aiocbs[2048], *out;
    static atomic_ulong digits = 2;
    (void) arg;
    for (out = &aiocbs[0];; ++out) {
        n = atomic_fetch_add_explicit(&digits, 1, memory_order_relaxed);
        p = calc_primes(n);
        /* digits majority minority location(1-indexed) */
        out->aio_fildes = STDOUT_FILENO;
        out->aio_offset = 0;
        out->aio_buf = buf[out - aiocbs];
        out->aio_nbytes = snprintf(buf[out - aiocbs], sizeof buf[0], "%lu %lu %lu %lu\n", n, p.maj, p.min, p.pos);
        out->aio_reqprio = 0;
        out->aio_sigevent.sigev_notify = SIGEV_NONE;
        aio_write(out);
    }
    /* unreachable */
    return NULL;
}
int
main(int argc, char *argv[])
{
    int opt, jobs;
    pthread_t t;
    extern char *optarg;
    jobs = 1;
    while ((opt = getopt(argc, argv, "j:")) > 0) {
        switch (opt) {
        case 'j':
            jobs = atoi(optarg);
            if (jobs > 0)
                break;
            /* fallthrough */
        default:
            fprintf(stderr, "usage: %s [-j jobs]\n", argv[0]);
            exit(EXIT_FAILURE);
        }
    }
    while (jobs --> 1) {
        pthread_create(&t, NULL, &job, NULL);
        pthread_detach(t);
    }
    job(NULL);
    /* unreachable */
    return 0;
}
```
[Try it online!](https://tio.run/##jVb7b5tIEP6dv2LUqinYkOL0Xg1JpFPrO0WK4lPanCrlLMRjwWvjXQ6WPHrKv36@2QcY25waS@Yxr29m@GYg8fIk2WxepySjjED4dfbH9Dr8PLu9@TiFn33fek1ZUjQpgbOI8uPFRU@Qr8tdQSkWFYnSXWEt0kjwNU0OxPvxUFTQeFfWMIpiKbPEU0kwTahF1SQCbkj5ieZUwD8W4K9hNc0ZSaHgLId1tAyGxJQNiUteB9ZzFzGwrFpEgiZbjCQqkrCs6JrU9q5vKvW1E7Qu95ymQBkVIWdovC6/hQIqXrrwAr/Rkse2vkKN1cJb34W3dBMMGkE0pXCBNeuhiqkLSxdWiNG6yZRru@96fXt15WjnbT1bg9roWuewJsJGOFfi93RRmmqv9uAY1IxXYFM4h0kAFM7O4UPQOag4XTAX9eNzOGkKGIE9wdNYeZ7De8dxDAFaPEwjbKhtipj4JpUOcaURV3Bm6tCo66bouZmTdHdhPF71QTqgJjZOKlHjQnt4HeYSMVcyX40InsxgaWoej5f74VXPM@V3jhEPdPKXcCYoa0hwoDVNHEhu6QSDONKjrHgcxZplYandfnSGsXMuOBCWDmMPN2Yf@9l6Wc79hmqfZ8tC7NOOYUlBomqXuypAj8AVEU3FwG4nChuuR6B7IKtnXAGWJYfPevn49uauoWHJH2T2ynziD8wJdqYz0FY9ZUrvyWOUiF2LD06XF4ys7X6IqrxF77ZUOTTqZuMli6iCuMnuTvwffpnfTX6aa7nZprjck1gfa23iwog3wsyqWVJ6kYdNrwXI7BNjpDJzADMLtgOOMdDkyET254EkPAr7lGdoYUJnRCQLyYSQPJYFTaiwjzQQNsuFNVnz6inkVUqqsCJF9EjSHj9KDNTflaynezdqM8aXA6@oeJKvA31R8ATr48yeeJSlRAaF0bvOFdP1LrCCMKNFSmTJn798mt1@CX@7vJpez4JDQ55luIfQ0B9Q4lNAjXwWsjme6fp8wJLFT0Lh1QwrYiKzD7xcqOk3wjMVz8fbV2@KBnr/v9grnAcXymOsW52ousOXnjMAWZG/EYr/T@pILHJPmDhWFyHjgmZPsh@Xv0//DK9n19Otk7R/wPYSyQED9ayZgs@iYfipgKSMC9K22gypHFvFeSzYWkeU2XghWZW4msWS@/d385b@UstLuWF4XGsY8yGCoyu0gDwKgqG1OxorjiqNdFJvBHX3sKCYj22jCQpzIvDC1tASFLu7PH2Fr5wL8PsErh8o0hakW1@cRDWBt8u3pzurziAi4amtU9nbjGrzSyOJcrBhY6xsteuA7cyiosCieZMv@szF76WoKcRuApnhEn5YkarCmpo6yskpvKnhzluq/OaKNarP/nwvPfKIQzn9eon0//Xy6vZmOrSge81UpXjeBS67Xm/aR5TgESlyZD44XDhC@53d3bdOiUDS2Ht0klvROHyfXr7k1maz8ZYn/yZZEeX1xpu933gGYuMV@F2Lx0r8Bw "C (gcc) – Try It Online") n ~ 700 (w/ `-j2`).
[Answer]
# [Python](https://docs.python.org/3/), with [gmpy2](https://gmpy2.readthedocs.io/en/latest/), n=920
~920 digits in 5 minutes on my Windows machine
```
import gmpy2
import time
def nrdprime(n):
    for j in range(1,10):
        for k in range(n, 0, -1):
            for l in range(10):
                if j == l: continue
                if l == 0 and k == 1: continue
                a = [j] * n
                a[k-1] = l
                if a[n-1] % 2 == 0: continue
                x = int(''.join(map(str, a)))
                if gmpy2.is_prime(x):
                    print(n, j, l, k)
                    return x
    print(n, "has no answer")
start_time = time.time()
i = 2
while time.time() - start_time < 300:  # Run for 300 seconds (5 minutes)
    nrdprime(i)
    i += 1
print(f"Processed up to n = {i-1} in 5 minutes.")
```
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 164 bytes, n = 839
```
f(n)=d=(10^n-1)/9;for(i=1,9,for(j=0,n-1,for(k=0,9,if(i!=k&&(k>0||j<n-1)&&((i*n+k-i)%3)&&ispseudoprime(p=d*i+(k-i)*10^j),return(p)))))
for(n=2,oo,print(n" -> "f(n)))
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY5NDoIwEIX3ngJJJFOYRtCNRMtRNCZQM21smwI7buKGhcYzeRtbf2b1Xl7em-_2dGdPp4ub58c4SL573SUYJloBVXk0vGLrei-tBxIV1hiVEiWG4KN10DWSBFoKnWWgm3Ka1CH2ggPKTaE5sdU2WOpd342tdZ6uHTjR5lRATPPwSTH03TB6A47FW8R1IzZoLYaCGcCkCW-SNNIx9mX9If_R3w)
The [`ispseudoprime`](https://pari.math.u-bordeaux.fr/dochtml/html/Arithmetic_functions.html#se:ispseudoprime) function uses [the BPSW primality test](https://en.wikipedia.org/wiki/Baillie%E2%80%93PSW_primality_test). Currently no counterexample is known.
The package name for PARI/GP is `pari-gp` on Ubuntu, Debian, Arch Linux and some other distros.
Runs as `gp -qf ./file_name.gp`.
[Answer]
# [C++ (gcc)](https://gcc.gnu.org/), n = 595
* Compile with `-O3 -pthread -lfmt`
```
#include <atomic>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/miller_rabin.hpp>
#include <fmt/core.h>
#include <thread>
namespace mp = boost::multiprecision;
struct RepDigit {
    int pos;
    char maj, min;
};
static std::atomic<int> digits{2};
static RepDigit
calcPrimes(int digits)
{
    static const mp::cpp_int ten{10};
    char buf[2048] = {};
    for (char i = '1'; i <= '9'; i += 2) {
        std::memset(buf, i, digits);
        mp::cpp_int num{buf};
        mp::cpp_int n{ten};
        for (int k = 1; k < digits; n *= ten, ++k) {
            for (char j = '9'; j >= '0'; --j) {
                if (j == i)
                    continue;
                num += n * (j - i);
                if (mp::miller_rabin_test(num, 10))
                    return {digits - k, i, j};
                num -= n * (j - i);
            }
        }
    }
    return {};
}
static void
job()
{
    for (;;) {
        auto n = digits.fetch_add(1);
        auto p = calcPrimes(n);
        /* digits majority minority location(1-indexed) */
        fmt::print("{} {} {} {}\n", n, p.maj, p.min, p.pos);
    }
}
int
main()
{
    for (auto hc = std::thread::hardware_concurrency(); hc > 1; --hc)
        std::thread{job}.detach();
    job();
}
```
No TIO link because it doesn't have [{fmt}](https://fmt.dev/latest/index.html).
]