[Question]
  [
## Challenge
Given an input integer `n > 0`, output the number of primes (*other* than `n`, if `n` itself is prime) that can be produced by altering one digit in the decimal expansion of n (without changing the number of digits).
## Examples
For example, `n = 2`. By altering one digit in the decimal expansion of `2`, we can come up with three additional prime numbers, `3, 5, 7`, so `a(n) = 3`.
For another example, `n = 13`. By altering one digit, you can get primes `11, 17, 19, 23, 43, 53, 73, 83`, so `a(13) = 8`.
For a final example, `n = 20`. By altering one digit, you can get primes `23, 29`, so `a(20) = 2`.
## Sequence
Here are the first 20 terms to get you started. This is OEIS [A048853](http://oeis.org/A048853).
`4, 3, 3, 4, 3, 4, 3, 4, 4, 4, 7, 4, 8, 4, 4, 4, 7, 4, 7, 2`
## Rules
* The input and output can be assumed to fit in your language's native integer type.
* The input and output can be given [in any convenient format](http://meta.codegolf.stackexchange.com/q/2447/42963).
* Ignore leading zeros (for example, `03` is not a prime number under this formulation).
* Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
* If possible, please include a link to an online testing environment so other people can try out your code!
* [Standard loopholes](http://meta.codegolf.stackexchange.com/q/1061/42963) are forbidden.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so all usual golfing rules apply, and the shortest code (in bytes) wins.
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~17~~ ~~16~~ ~~14~~ 11 bytes
```
ā°`<Ÿʒ.L}pO
```
Explanation:
```
ā             Push inclusive range from 1 to the length of the input
 °            Raise 10 to the power of each element
  `           Push each element to the stack
   <          Decrement the topmost element
    Ÿ         Inclusive range
              For 13, this creates an array like [10 11 12 13 14 .. 98 99]
     ʒ.L}     Only keep elements with a levenshtein distance to the input of
              exactly one
         p    Check each element for primality
          O   Sum
```
[Try it online!](https://tio.run/##MzBNTDJM/f//SOOhDQk2R3ecmqTnU1vg//@/oTEA "05AB1E – Try It Online") or [up to 100](https://tio.run/##MzBNTDJM/e9TVmmvpKBrp6BkX/n/SOOhDQk2R3ecmlSp51Nb4P9f57@hgQEA "05AB1E – Try It Online").
[Answer]
# [Python 2](https://docs.python.org/2/), ~~146 136 127 121~~ 118 bytes
Thanks to @Mr.Xcoder for suggestions
```
lambda I:sum(all(i%v for v in range(2,i))*sum(z!=x for z,x in zip(I,`i`))==1for i in range(1+10**~-len(I),10**len(I)))
```
Explanation:
Generate numbers with length equal to input length, skipping first (1,10,100,1000,... )
```
for i in range(1+10**~-len(I),10**len(I))
```
Check that generated number differs from input by only one digit
```
sum(z!=x for z,x in zip(I,`i`))==1
```
Check for prime
```
all(i%v for v in range(2,i))
```
Count 
```
sum(...)    
```
[Try it online!](https://tio.run/##tVHRSsMwFH3PV1yR0qTLoEk7LYX4Ij4UBj746IarWF2gTUubzdkHf72alGzVgW/C5XBzzr03cE7zobe14sNSrIYyr55fcsjSblfhvCyx9PbwWrewB6mgzdVbgTmVhARmoL8QB6v29GD0XjY4oxu5IUQIZgR5WmMzFgbB57wsFM4INY@xJWT4PUo5IymCppVKg6T@/ManS2wOI3R/lz2AgMeYQmQr/oljXVtMzphv5A6vLPIJs5hgMlEXbiayW5HrowmT/MPlxPF/X2aWZ5ZhrmLHmyac2rFGun7SRaeNjaOtcJaAycZYTWaMrBEao/BX6raumrwt4F3qLdgsdg3oGi69LvW94xaF4x/Cjg08/AI)
[Answer]
# Javascript (ES6) 148 bytes
Takes the input as a string and returns as a number
```
n=>(n.replace(/./g,"$`a$' ").split` `.map(s=>s&&[..."0123456789"].map(d=>r+=+(t=s.replace(/a/,d))[0]&&t^n&&(p=v=>t>1&(--v<2||t%v&&p(v)))(t)),r=0),r)
```
**Example code snippet:**
```
f=
n=>(n.replace(/./g,"$`a$' ").split` `.map(s=>s&&[..."0123456789"].map(d=>r+=+(t=s.replace(/a/,d))[0]&&t^n&&(p=v=>t>1&(--v<2||t%v&&p(v)))(t)),r=0),r)
for(var k=1;k<=20;k++)
  o.innerText+=f(""+k)+" "
```
```
<pre id=o></pre>
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~21~~ ~~18~~ 15 bytes
3 bytes thanks to Dennis.
```
æḟ⁵æR×⁵$DnDS€ċ1
```
[Try it online!](https://tio.run/##y0rNyan8///wsoc75j9q3Hp4WdDh6UBaxSXPJfhR05oj3Yb///83NAYA "Jelly – Try It Online") or [Verify all testcases](https://tio.run/##y0rNyan8///wsoc75j9q3Hp4WdDh6UBaxSXPJfhR05oj3Yb/jQwOtwOZ/wE).
[Answer]
# Mathematica, 105 bytes
```
F=Count[Range[f=IntegerDigits;g=10^Length@f@#/10,10g],n_/;PrimeQ@n&&MatchQ[f@n-f@#,{x=0...,_,x}]&&n!=#]&;
```
[Try it online!](https://tio.run/##Jc3BCsIgGADgV1kMPNnUriIIjUFQ0LqKDRn662F/sBkMomc3ofsH3@JyTPNWyqDOrzdm83AI3gR1wezBr32ClDcJSvDn1SPkqINumeBUcLAUJybva1r8qJGQm8tzHE3QeKyIfnbFu66jE92/lhA8qNYSWaqvz9Aw3fyzE7e2/AA "Mathics – Try It Online")
`Function` which expects a positive integer `#`. Sets `f` equal to the function `IntegerDigits` which returns the list of digits of its input. We take the `Range` from `g` to `10g` (inclusive), where `g=10^Length@f@#/10` is the largest power of `10` less than or equal to the input `#`, then `Count` the `n` such that `PrimeQ@n&&MatchQ[f@n-f@#,{x=0...,_,x}]&&n!=#`. `PrimeQ@n` checks whether `n` is prime, `MatchQ[f@n-f@#,{x=0...,_,x}]` checks whether the difference between the list of digits of `n` and `#` is of the form `{0..., _, 0...}`, and `n!=#` ensures that `n` and `#` are `Unequal`.
[Answer]
# JavaScript (ES6), ~~153~~ ~~142~~ 139 bytes
```
n=>([...n].map((c,i,[...a])=>[...''+1e9].map((u,j)=>s+=j+i&&j!=c?p((a.splice(i,1,j),a.join``)):0),s=0,p=q=>eval('for(k=q;q%--k;);k==1')),s)
```
Accepts input as a string. Undefined behavior for invalid input, though it should terminate without error on any string I can think of. Not necessarily before the heat-death of the universe though, particularly for long strings.
### Demo
```
f=
n=>([...n].map((c,i,[...a])=>[...''+1e9].map((u,j)=>s+=j+i&&j!=c?p((a.splice(i,1,j),a.join``)):0),s=0,p=q=>eval('for(k=q;q%--k;);k==1')),s)
console.log([...''+1e19].map((_,i)=>f(i+1+'')).join())
i.onchange=()=>console.log(f(i.value))
```
```
<input id=i>
```
### Improvements
Saved 11 bytes by refactoring the `reduce()` calls into `map()` calls, and by implicitly copying the array `a` in the function parameter, instead of in within the context of the `splice()` call.
Saved 3 bytes thanks to [@Neil](https://codegolf.stackexchange.com/questions/137195/primes-other-than-optimus/137270#comment336215_137270)'s suggestion to convert `[...Array(10)]` to `[...''+1e9]`.
### Unminified code
```
input => (
  [...input].map(
    (char, decimal, [...charArray]) =>
      [...'' + 1e9].map(
        (unused, digit) => sum +=
          digit + decimal && digit != char ?
            prime(
              (
                charArray.splice(decimal, 1, digit)
                , charArray.join``
              )
            ) :
            0
      )
    , sum = 0
    , prime = test => eval('for(factor = test; test % --factor;); factor == 1')
  )
  , sum
)
```
### Explanation
The function uses a two-level `map()` to sum the amount of permutations that pass the primality test, which was borrowed and modified from [this answer](https://codegolf.stackexchange.com/questions/57617/is-this-number-a-prime/91309#91309).
### (Original answer)
```
reduce((accumulator, currentValue, currentIndex, array) => aggregate, initialValue)
```
So for example, to calculate the sum of an array, you would pass an `initialValue` of `0`, and return an `aggregate` equal to `accumulator + currentValue`. Modifying this approach slightly, we instead calculate the number of permutations that pass the primality test:
```
reduce(
  (passedSoFar, currentDecimal, currentIndex, digitArray) =>
    isValidPermutation() ?
      passedSoFar + prime(getPermutation()) :
      passedSoFar
  , 0
)
```
That is essentially the inner `reduce()`, which iterates all the permutations of the `digitArray` by changing each `decimal` to a specific `permutatedDigit`. We then need an outer `reduce()` to iterate all possible `permutatedDigit`'s with which to replace each `decimal`, which is just `0-9`.
### Abnormalities in implementation
`[...''+1e9].map((u,j)=>...` was the shortest way [@Neil](https://codegolf.stackexchange.com/questions/137195/primes-other-than-optimus/137270#comment336215_137270) could think of to iterate an argument `0` through `9`. It would be preferable to do so with `u`, but `u` is not useful for each element in the array, in this case.
`i+j` in the ternary condition checks to ensure that `0` is not a possible permutation of the leading digit, as per the challenge specification. `j!=c` ensures that the original `n` is not a candidate to go through the primality test.
`(a.splice(i,1,j),a.join``)` is kind of a mess. `splice()` replaces the digit at `decimal == i` with the `permutatedDigit == j`, but since `splice()` returns the removed elements (in this case, would be equal to `[a[i]]`) instead of the modified array, we must use the comma operator to pass the modified array `a` to the primality test, but not before `join()`ing it into a number string.
Lastly, the `eval()` is to save a byte since, compared to the more canonical approach, it is shorter:
```
q=>eval('for(k=q;q%--k;);k==1')
```
```
q=>{for(k=q;q%--k;);return k==1}
```
The reference to the prime test `p` is initialized in an unused argument to the `map()` call.
[Answer]
# [Python 2](https://docs.python.org/2/), 134 bytes
```
lambda x,r=range,l=len:sum(~-f*(~-l(x)==sum(`f`[t]==x[t]for t in r(l(x))))and all(f%v for v in r(2,f))for f in r(10**~-l(x),10**l(x)))
```
[Try it online!](https://tio.run/##JU5BCsIwELz7ir1Ik7IFm2MhfkSFRNpoYJuWGEu9@PWYNXMYdnZmll0/6bkElUlfM9n5PlrYMepow2NC0jSF4fWexbdzbSESu9SaF8aZS7ppvRd2S4QEPkAUHCiwYQRLJNxxA3a36ip0UrJ2Vfentq1Hkcdazhzw/wA/IXpUvRwOULBGHxIYbxCa7twgkChC5h8 "Python 2 – Try It Online")
More elegant, longer version:
```
lambda x,r=range,l=len:l(filter(lambda f:(~-f*(~-l(x)==sum(`f`[t]==x[t]for t in r(l(x)))))*all(f%v for v in r(2,f)),r(10**~-l(x),10**l(x))))
```
The input is taken as a String.
---
# Explanation (older version)
* `lambda x,r=range,l=len:` - Defines a lambda with a String parameter `x` and two constant parameters `r=range` and `l=len`.
* `sum(1...)` - Get the length, which saves 1 byte over `len([...])`.
* `for f in r(10**~-l(x),10**l(x))` - Generates absolutely all the numbers with the same order of magnitude as the input (expect for `0`). For instance, an input of `3`, would result in `[1, 2, 3, 4, 5, 6, 7, 8, 9]`.
* `sum(1for t in r(l(x))if`f`[t]==x[t])==~-l(x)and f>1` - Checks if the current number is exactly 1 digit away from the input, and that it is higher than 1.
* `all(f%v for v in r(2,f))` - Checks if the current number is prime.
[Answer]
# [Husk](https://github.com/barbuz/Husk), 32 bytes
```
Lof§&ȯ=1Σzo±≠d⁰o=Ld⁰L↑o≤Ld⁰Lmdİp
```
[Try it online!](https://tio.run/##yygtzv6f@6ip8eGOxf998tMOLVc7sd7W8NziqvxDGx91Lkh51Lgh39YHRPk8apuY/6hzCYSTm3JkQ8H///@NDAA "Husk – Try It Online")
### Ungolfed/Explanation
```
                              İp  -- get all primes
                            md    -- and convert them to list of digits
                     ↑o≤   L      -- take as long as the lenghth of these digit lists are ≤ ..
                        Ld⁰       -- .. the number of digits of input 
 of                               -- from those primes filter:
               o=Ld⁰L             --   same number of digits as input
   §&                             --   and
        Σz                        --   the number of..
          o±≠d⁰                   --   .. digits that differ from input digits ..
     ȯ=1                          --   .. must be one
L                                 -- finally count them
```
[Answer]
# JavaScript (ES6), 137 bytes
```
i=(a=prompt()).length;s=0;while(i--)for(j=0;j<=9;j++){(b=[...a]).splice(i,1,j);k=b=b.join('');while(b%--k);s+=i+j&&a[i]!=j&&k==1}alert(s)
```
Adapts [my other answer](https://codegolf.stackexchange.com/a/137270/42091) into a full-program submission using the Web API methods `prompt()` and `alert()`.
[Answer]
# [Bean](https://github.com/patrickroberts/bean), 126 bytes
```
00000000: a64d a065 8050 80a0 5d20 8001 a64d a06f  ¦M e.P. ] ..¦M o
00000010: 8025 39b5 cb81 2065 27a6 4da0 6680 2581  .%9µË. e'¦M f.%.
00000020: 0035 cb81 2066 27a6 53d0 80cd a05e 8043  .5Ë. f'¦SÐ.Í ^.C
00000030: cf20 5d00 2080 82a0 65a5 3a20 66a6 4da0  Ï ]. .. e¥: f¦M 
00000040: 6780 4da0 5e80 53d0 80a0 5e20 807b 2300  g.M ^.SÐ. ^ .{#.
00000050: b5cc a05e 8f4b c120 6728 264d a06f 814e  µÌ ^.KÁ g(&M o.N
00000060: cecc a065 8b20 6681 4cd0 84a0 5d20 6581  ÎÌ e. f.LÐ. ] e.
00000070: 2066 814c a067 8025 3a26 206f b130        f.L g.%:& o±0
```
[Try it online!](https://tio.run/##RZE7UsMwEIZ7TrEzTALVjqyXlbSUEIYZ6jAjyXK65ABU1DyP4AZ6ilxAPpjZVeSgwl6N7G@//RWS30@TqGsN3uoOvLAGnDCCHl6A6SRXojmf9gD5Z5OHhA@Yhy0glu3h4oRpCOSENKBWwUAMrgHJSNl6C7ojpLVOgDR0ALhY5eP4ipCuCqTHBVaOJI4Q6h9hTwijOhaK7GISVVoRxzCkJ8jj@IXjex6e8KaCFIFiL3kUQX0FNXeSNYwnSS9ZaFaD8RO2yCMNKX@voS9WFaQJZFv6vXxqElVVpmxLTm0AqagN7HDDEqxDb8Dny3kwQ5hgYqz@vQ4QG7ZopQN5Dtk1OlHSx/GNObfjC@yul5wz3leQ5cFSAfGVhTIJZaUjS@n58mxJevxgUKKQ8K44bSHNRi2BSsDUs9DaeoNeWj7oITSKZjotAuRhh4v1Eg75V0yT@QM "Bean – Try It Online")
An adaption of [my full-program JavaScript submission](https://codegolf.stackexchange.com/a/137280/42091).
### JavaScript Equivalent
```
i=a.length
s=0
while(i--){
  j=10
  while(j--){
    (b=[...a]).splice(i,1,j)
    k=b=b.join('')
    while(b%--k);
    s+=i+j&&a[i]!=j&&k==1
  }
}
s
```
### Explanation
`a` is implicitly initialized as the first line of input as a string and the last statement `s` is implicitly output, which contains the sum of prime permutations.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~28~~ 23 bytes
*-5 bytes thanks to @ETHproductions.*
```
¬x@AÇ|Y©+UhYZsÃâ kUn)èj
```
Takes a string as input.
[Try it online!](https://codepen.io/justinm53/full/NvKjZr?code=rHhAQcd8WakrVWhZWnPD4iBrVW4p6Go=&inputs=IjEi,IjIi,IjMi,IjQi,IjUi,IjYi,Ijci,Ijgi,Ijki,IjEwIg==,IjExIg==,IjEyIg==,IjEzIg==,IjE0Ig==,IjE1Ig==,IjEwMCI=,IjE1MCI=,IjIwMCI=)
[Answer]
# [PHP](https://php.net/), ~~151~~ ~~147~~ ~~141~~ ~~140~~ ~~136~~ ~~134~~ ~~129~~ 128 bytes
*-6 bytes thanks to @Einacio; -1 byte thanks to @Titus*
```
<?php for($i=$m=10**strlen($n=$argv[1]);$i-->$m/10;)if(levenshtein($n,$i)==$f=$t=1){while($t<$i)$f+=$i%$t++<1;$c+=$f==2;}echo$c;
```
[Try it online!](https://tio.run/##FcpNDsIgEAbQq7j4TKDYyLilowcxLgwBmaQ/hJK6MJ4d7fbl5ZRbG2455UNcioIwJibbdWstY5gVZsazvLY7PbSD9P0V05ms0xLVGLYwr6kG2d8JopkRGZVJf95JxqBQhz8jGoYcUY0ZyMGbvfHFfYNPC7xrrZGlHw "PHP – Try It Online")
Formatted, with comments:
```
<?php
// Work through each integer with the same number of digits as the input $argv[1].
for ($i = $m = 10 ** strlen($n = $argv[1]); $i-- > $m / 10;)
    // Is it exactly one digit different from the input?
    if (levenshtein($n, $i) == $f = $t = 1) {
        // Count its factors.
        while ($t < $i) $f += $i % $t++ < 1;
        // If there are exactly 2 factors then it's a prime, so increment the counter.
        $c += $f == 2;
    }
// Print the final count.
echo $c;
```
To keep it as short as I could, I've:
* combined assignments `$f = $t = 1`;
* snook in a `++` increment as part of another expression `$f += $i % $t++ == 0` (the increment is executed *after* the modulus operation and so does not affect its result);
* and rather than using an `if` statement for a conditional increment have utilised the fact that boolean true when cast as an integer becomes 1, using `$c += $f == 2;` rather than `if ($f == 2) $c++;`.
[Answer]
# [Perl 6](http://perl6.org/), 83 bytes
```
{+grep &is-prime,m:ex/^(.*)(.)(.*)$/.map:{|map
.[0]~*~.[2],grep *-.[1],?.[0]..9}}
```
[Try it online!](https://tio.run/##HYtLCoMwGAav8iNBNI2fj0WhFtuDhFRcJEUwNMRNJY1XT2s3M4thnPbLOdmNckNDCqen147yea2cn60Wttfv@lGAlwXKQ6yGnVwfPj8SZKN2vkN2SvxHXkG2StyPAFxiTOu0UcZGGm4UDLExZmRenlqga67pCw "Perl 6 – Try It Online")
[Answer]
# PHP, 100+1 bytes
```
for(;~($a=$argn)[$i];$i++)for($d=-!!$i;$d++<9;$c+=$k==1)for($a[$i]=$d,$k=$a;--$k&&$a%$k;);echo$c-$i;
```
Run as pipe with `-nR` or [try it online](http://sandbox.onlinephpfunctions.com/code/13a9bfa8ff90bc831f210f4ad3c3aac66e4d5f17).
**breakdown**
```
for(;~($n=$argn)[$i];$i++)  # loop through argument digits, restore $n in every iteration
    for($d=-!!$i;               # loop $d from 0 (1 for first digit)
        $d++<9;                 # ... to 9
        $c+=$k==1                   # 3. if divisor is 1, increment counter
    )
        for($n[$i]=$d,              # 1. replace digit
            $k=$n;--$k&&$n%$k;      # 2. find largest divisor of $n smaller than $n
        );
echo$c-$i;                  # print counter - length
```
[Answer]
# Java 8, ~~201~~ 194 bytes
```
n->{String s=n+"";int r=0,i=0,j,k,t,u,l=s.length();for(;i<l;i++)for(j=0;++j<10;r+=n==u|t<2?0:1)for(u=t=new Integer(s.substring(0,i)+j+(i<l?s.substring(i+1):"")),k=2;k<t;t=t%k++<1?0:t);return r;}
```
**Explanation:**
[Try it here.](https://tio.run/##bVGxbsMgEN37FSekSiCIZXsMppk7NEvGqoPj0BTbwREcqao03@6e7QyVWokD3T3uHe/R1pd6NZytbw/d2PR1jPBSO399AHAebXivGwvbKZ0L0PBp90JT5UZBK2KNroEteDAw@tXTdYfB@SNE4yVjemoIJleOolWdQpVUb2LWW3/EDy70@xC4dlWvnZRiSlqTaynbqsh1kMYbk76xKjf5upjhZNB4@wnP9MCjDTxmMe3jPJPTGCFbyYlu87vuZCHWjAmhOlPqrkKNBh87KauCeFHoYDEFD0HfRr3oOqd9T7ru8i6DO8CJrOGLutc3qMXiy/SmSaQzhQZXmTKng6QsKMDuK6I9ZUPC7EytyH1GNgqQwBSw2crFzL9Xe8/v@D8IK/N8DYx4JkJKxP1bbuMP)
```
n->{                        // Method with integer as parameter and return-type
  String s=n+"";            //  String representation of the input-int
  int r=0,                  //  Result-integer
      i=0,j,k,              //  Index-integers
      t,u,                  //  Temp integers
      l=s.length();         //  Length of the String
  for(;i<l;i++)             //  Loop (1) from 0 to `l` (exclusive)
    for(j=0;++j<10;         //   Inner loop (2) from 1 to 10 (exclusive)
        r+=                 //     And after every iteration, raise the result by:
           n==u             //      If the current number equals the input
           |t<2?            //      or it is not a prime:
            0               //       Add nothing to the result-counter
           :                //      Else:
            1)              //       Raise the result-counter by one
      for(                  //    Inner loop (3)
          u=t=              //     First set both `u` and `t` to:
              new Integer(  //      Convert the following String to an integer: 
               s.substring(0,i)
                            //       Get the substring from 0 to `i` (exclusive)
               +j           //       + `j`
               +(i<l?       //       + If `i` is smaller than the String-length:
                  s.substring(i+1)
                            //          The substring from 0 to `i` (inclusive)
                 :          //         Else:
                  "")),     //          Nothing
          k=2;              //     And start `k` at 2
              k<t;          //     Continue looping as long as `k` is smaller than `t`
        t=t%k++<1?          //     If `t` is divisible by `k`:
           0                //      Change `t` to 0
          :                 //     Else:
           t                //      Leave `t` as is
      );                    //    End of inner loop (3)
                            //    (`t` remained the same after loop 3? -> It's a prime)
                            //   End of inner loop (2) (implicit / single-line body)
                            //  And of loop (1) (implicit / single-line body)
  return r;                 //  Return the result-counter
}                           // End of method
```
`new Integer(s.substring(0,i)+j+(i<l?s.substring(i+1):"")` will result in these integers:
For `0-9`: `1, 2, 3, 4, 5, 6, 7, 8, 9`.  
For `10`: `10, 20, 30, 40, 50, 60, 70, 80, 90, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19`.  
For `11`: `11, 21, 31, 41, 51, 61, 71, 81, 91, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19`.  
etc.
[Answer]
# JavaScript (ES7), 118 bytes
Takes input as a string.
```
n=>[...2**29+'4'].map(d=>n.replace(/./g,c=>s+=d+i>0&(P=k=>N%--k?P(k):N-n&&k==1)(N=p+d+n.slice(++i),p+=c),i=p=0),s=0)|s
```
[Try it online!](https://tio.run/##DYvBjoIwFEX3fkUXCn0@qGCchTqv8wfE/WQSmwKmA742dOIG@Xamm3PP4p5f8zLRTi78lezbbu1pZdLfSqnjfn88Y37Kf9TTBNmSZjV1YTS2kwd1eBSWdERq0ekqkzcaSDe7shy@bnKAS1Nylg1ENciGArbIKo4upYgOioBkoXAUqIIiJrzj2vtJsiBRXwWLz7TVRzJEEPNGCOs5@rFTo3/Iu5HbmRdI5@3cpwhFnsNyh@tmWf8B "JavaScript (Node.js) – Try It Online")
### Commented
```
n =>                        // n = input number (as a string)
  [...2**29 + '4']          // generate "5368709124" (all decimal digits)
  .map(d =>                 // for each digit d in the above string:
    n.replace(/./g, c =>    //   for each digit c in n:
      s +=                  //     increment s if the following code yields 1:
        d + i > 0 & (       //       if this is not the first digit of n or d is not "0":
          P = k =>          //         P = recursive function taking k and using N:
            N % --k ?       //           decrement k; if k is not a divisor of N:
              P(k)          //             do recursive calls until it is
            :               //           else:
              N - n &&      //             return true if N is not equal to n
              k == 1        //             and k is equal to 1 (i.e. N is prime)
          )(                //         initial call to P ...
            N =             //           ... with N defined as:
              p +           //             the current prefix p
              d +           //             followed by d
              n.slice(++i), //             followed by the trailing digits
                            //             (and increment the pointer i)
            p += c          //           append c to p
          ),                //         end of initial call
          i = p = 0         //         start with i = p = 0
    ),                      //   end of replace()
    s = 0                   //   start with s = 0
  ) | s                     // end of map(); return s
```
[Answer]
# [Ruby](https://www.ruby-lang.org/) with `-rprime`, 101 bytes
`-rprime` imports the Prime module into Ruby. Get all primes up to \$10^{floor(log\_{10} n)+1}\$ and count how many have the same number of digits from \$n\$ and are also 1 digit off.
```
->n{d=n.digits;Prime.each(10**l=d.size).count{|x|d.zip(e=x.digits).count{|a,b|a==b}==l-1&&e.size==l}}
```
[Try it online!](https://tio.run/##PY1LCsIwFAD3PYULKbWY0NalPM/gXqWkTaoPahLygdomVzd@EJfDMIzx3SMNcE7kIBcOknK8orP7o8G7oIL1t6KuynIETi3OYkN75aVbwhQ4nVEXAqZf8lds2wUG0EWAkdR5Lr7lG2JM2ju7Gk7rljrV4iU1Wb3LmuqptEMlbSIyEaM/7xc "Ruby – Try It Online")
]