| Bytes | Lang | Time | Link |
|---|---|---|---|
| 157 | Rust | 240917T104954Z | bzr |
| 036 | Charcoal | 240918T005444Z | Neil |
| 011 | Japt | 240916T223015Z | Shaggy |
| 059 | JavaScript ES6 | 240916T201812Z | Arnauld |
| 5625 | Vyxal gr | 240916T201441Z | pacman25 |
| 130 | SageMath | 240917T105516Z | Sophia A |
| 009 | Brachylog | 240917T093109Z | Fatalize |
| 069 | Ruby | 240917T075106Z | G B |
| 008 | 05AB1E | 240917T071811Z | Kevin Cr |
| 097 | Python | 240916T201904Z | TheLittl |
Rust, 167 159 158 157 bytes
-1 byte thanks to ceilingcat
let g=|n|{if n==2{return 1}for i in 2..n{if n%i<1{return 0}}1};let f=|p:i32|{for q in 2..{if g(q)>0&&g(format!("{}{q}",p+q).parse().unwrap())>0{return q}}0};
Charcoal, 36 bytes
Nθ≔³ηW⊙⟦ηI⁺I⁺ηθIη⟧⊙…¹÷견﹪κ⊕⊗μ≧⁺²ηIη
Try it online! Link is to verbose version of code. Explanation:
Nθ
Input p.
≔³η
Start with q=3.
W⊙⟦ηI⁺I⁺ηθIη⟧⊙…¹÷견﹪κ⊕⊗μ
Check that both p and (q+p)&q are prime by trial division of all odd numbers.
≧⁺²η
If not then add 2 to q and try again.
Iη
Output the found value of q.
The golfiest code I could find was to switch to Wilson's theorem for prime checking but this is even slower than odd divisor checking, however it does at least let me save a further byte (and cause even more slowdown) by checking all integers rather than odd ones:
Nθ≔³ηW⊙⟦ηI⁺I⁺ηθIη⟧﹪⊕Π…²κκ≦⊕ηIη
Try it online! Link is to verbose version of code. Only shows an input of p=11 as the given test case would take too much time to compute (even p=419 is too slow).
Japt, 13 11 bytes
@°s+X*j)j}a
Try it, run all test cases or check the first 1000 terms
@°s+X*j)j}a :Implicit input of integer U
@ :Function taking an integer X as argument
° : Postfix increment U
s+ : Convert to string and append
X* : X multiplied by
j : Is X prime?
) : End string conversion and convert back to int
j : Is result prime?
} :End function
a :Get the first integer >=0 that returns truthy
JavaScript (ES6), 59 bytes
p=>eval("for(d=q=1;q<d--|q%d&&n%d?1:d=n=d-1&&[++q+p]+q;)q")
faster / more readable, 61 bytes
p=>{for(d=q=1;q<d--|q%d&&n%d?1:d=n=d-1&&[++q+p]+q;);return q}
p => { // p = input prime
for( // loop:
d = // d = divisor
q = 1; // q = the prime we're looking for
q < d-- | // if q is less than d (decrement d afterwards)
q % d // or d is not a divisor of q
&& // AND
n % d ? // q is not a divisor of n:
1 // keep searching
: // else:
d = n = // update d and n:
d - 1 // if d is not equal to 1 (meaning that
&& // either q or n is composite):
[++q + p] + // increment q and build the new
q; // candidate number
); // end of for()
return q // return q
} //
recursive, 55 bytes
p=>(g=d=>q<d--|q%d&&n%d?g(d):d-1?g(n=[++q+p]+q):q)(q=1)
Vyxal gr, 45 bitsv2, 5.625 bytes
Þp'⁰+Jæ
Bitstring:
001010110100000101000111110000010010001101100
Þp'⁰+Jæ
Þp # a list of infinite primes
' # filtered by
⁰+ # (p+q)
J # (p+q)"q
æ # is prime
💎
Created with the help of Luminespire. Try it Online!
Bitstring:
00101011010000010100011111000101000101101101110110
7 bytes without vyncode, some filter magic.
-1 from r flag
SageMath, 130 bytes
def g(p):
for q in Primes():
if is_prime(q+(p+q)*10^(1+int(log(q)/log(10)))):return q
print([g(p) for p in prime_range(100)])
Brachylog, 9 bytes
;.+;.cṗ∧ṗ
Explanation
;.+ Input + Output…
;.c …concatenated with Output…
ṗ …is prime…
∧ṗ …and Output itself is prime
05AB1E, 8 bytes
∞Ø.Δ+y«p
Try it online or verify all test cases.
Explanation:
∞ # Push an infinite positive list: [1,2,3,...]
Ø # Map each to their 0-based n'th prime number: [3,5,7,...]
.Δ # Find the first prime in this list that's truthy for:
+ # Add it to the (implicit) input-integer
y« # Append the current prime to this sum
p # Check if that is a prime itself
# (after which the found result is output implicitly)
Although we skip prime 2 in the infinite list, since the infinite list starts at 1 and the n'th prime builtin is 0-based, it doesn't matter for the challenge, since appending a 2 to the sum will always result in an even number, and therefore never a prime.
Python, 97 bytes
g=lambda x:all(x%i for i in range(2,x))
f=lambda p,q=2:q if g(q)*g(int(f'{p+q}{q}'))else f(p,q+1)